#define physics_cxx
// The class definition in physics.h has been generated automatically
// by the ROOT utility TTree::MakeSelector(). This class is derived
// from the ROOT class TSelector. For more information on the TSelector
// framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.

// The following methods are defined in this file:
//    Begin():        called every time a loop on the tree starts,
//                    a convenient place to create your histograms.
//    SlaveBegin():   called after Begin(), when on PROOF called only on the
//                    slave servers.
//    Process():      called for each event, in this function you decide what
//                    to read and fill your histograms.
//    SlaveTerminate: called at the end of the loop on the tree, when on PROOF
//                    called only on the slave servers.
//    Terminate():    called at the end of the loop on the tree,
//                    a convenient place to draw/fit your histograms.
//
// To use this file, try the following session on your Tree T:
//
// Root > T->Process("physics.C")
// Root > T->Process("physics.C","some options")
// Root > T->Process("physics.C+")
//


#include "physics.h"
#include "TROOT.h"
#include <TH2.h>
#include <TStyle.h>


TTree *m_tree;
   Int_t           h_jet_n;
   vector<float>   *h_jet_E;
   vector<float>   *h_jet_pt;
   vector<float>   *h_jet_pt_ori;
   vector<float>   *h_jet_eta;
   vector<float>   *h_jet_phi;
   vector<float>   *h_jet_weight;
   vector<float>   *h_jet_jvf;
   vector<float>   *h_jet_bad;
   vector<float>   *h_jet_Btagsf;
   vector<float>   *h_jet_Btagsferr;
   vector<float>   *h_jet_Btagsf_0;
   vector<float>   *h_jet_Btagsferr_0;
   vector<float>   *h_jet_Btagsf_1;
   vector<float>   *h_jet_Btagsferr_1;
   vector<float>   *h_jet_Btagsf_2;
   vector<float>   *h_jet_Btagsferr_2;
   vector<float>   *h_jet_Btagsf_3;
   vector<float>   *h_jet_Btagsferr_3;
   vector<float>   *h_jet_Btagsf_4;
   vector<float>   *h_jet_Btagsferr_4;
   vector<float>   *h_jet_ResFactor;
   vector<float>   *h_jet_ResFactorSys;
   vector<float>   *h_jet_ScaleUncertUp;
   vector<float>   *h_jet_ScaleUncertDo;
   vector<float>   *h_jet_ScaleUncertNPV;
   vector<float>   *h_jet_ScaleUncertMU;
   vector<bool>    *h_jet_Pass_LowPt;
   vector<bool>    *h_jet_Pass_HighPt;
   vector<bool>    *h_jet_Pass_TightCut;
   vector<int>    *h_jet_label;


   Int_t           h_elec_n;
   vector<float>   *h_elec_E;
   vector<float>   *h_elec_pt;
   vector<float>   *h_elec_pt_ori;
   vector<float>   *h_elec_pt_up;
   vector<float>   *h_elec_pt_down;
   vector<float>   *h_elec_pt_Rup;
   vector<float>   *h_elec_pt_Rdown;
   vector<float>   *h_elec_eta;
   vector<float>   *h_elec_phi;
   vector<float>   *h_elec_sumpt;
   vector<float>   *h_elec_sumet;
   vector<float>   *h_elec_charge;
   vector<float>   *h_elec_mt;
   vector<float>   *h_elec_sf;
   vector<float>   *h_elec_sf_err;
   vector<float>   *h_elec_recsf;
   vector<float>   *h_elec_recsf_err;
   vector<float>   *h_elec_trig_e20;
   vector<float>   *h_elec_trig_e22;
   vector<float>   *h_elec_trig_e22vh;
   vector<bool>    *h_elec_Pass_LowPt;
   vector<bool>    *h_elec_Pass_HighPt;
   vector<bool>    *h_elec_Pass_TightCut;
   vector<bool>    *h_elec_medium;
   vector<bool>    *h_elec_tight;

   Int_t           h_muon_n;
   vector<float>   *h_muon_E;
   vector<float>   *h_muon_pt;
   vector<float>   *h_muon_pt_id;
   vector<float>   *h_muon_pt_ms;
   vector<float>   *h_muon_pt_ori;
   vector<float>   *h_muon_pt_ms_up;
   vector<float>   *h_muon_pt_id_up;
   vector<float>   *h_muon_pt_ms_down;
   vector<float>   *h_muon_pt_id_down;
   vector<float>   *h_muon_pt_MS_ms_up;
   vector<float>   *h_muon_pt_MS_id_up;
   vector<float>   *h_muon_pt_MS_ms_down;
   vector<float>   *h_muon_pt_MS_id_down;
   vector<float>   *h_muon_pt_ID_ms_up;
   vector<float>   *h_muon_pt_ID_id_up;
   vector<float>   *h_muon_pt_ID_ms_down;
   vector<float>   *h_muon_pt_ID_id_down;
   vector<float>   *h_muon_eta;
   vector<float>   *h_muon_phi;
   vector<float>   *h_muon_sumpt;
   vector<float>   *h_muon_sumet;
   vector<float>   *h_muon_charge;
   vector<float>   *h_muon_theta;
   vector<float>   *h_muon_mt;
   vector<float>   *h_muon_sf;
   vector<float>   *h_muon_sf_Sta_err;
   vector<float>   *h_muon_sf_Sys_err;
   vector<float>   *h_muon_energyloss;
   vector<bool>   *h_muon_not_overlap;
   vector<bool>    *h_muon_Pass_LowPt;
   vector<bool>    *h_muon_Pass_HighPt;
   vector<bool>    *h_muon_Pass_TightCut;
   vector<bool>    *h_muon_isCombine;
   vector<bool>    *h_muon_isStandAlone;
   vector<bool>    *h_muon_isCalo;
   vector<bool>    *h_muon_medium;
   vector<bool>    *h_muon_tight;
   float    h_muon_trigsf;
   float    h_muon_trigsfsys;


   Int_t h_RunNumber;
   Int_t h_EventNumber;
   Int_t h_lbn;
   Int_t h_mu;

   Int_t h_EF_mu18_MG;
   Int_t h_EF_e20_medium;
   Int_t h_EF_xe80T_tclcw_loose;
   Int_t h_EF_xe80_tclcw_loose;
   float h_met; 
   float h_met_box; 
   float h_met_CellOutUp;
   float h_met_CellOutDo;
   float h_met_SoftJetUp;
   float h_met_SoftJetDo;
   float h_met_SoftJetResoUp;
   float h_met_SoftJetResoDo;
   float h_stvf_CellOutUp;
   float h_stvf_CellOutDo;
   float h_stvf_SoftJetUp;
   float h_stvf_SoftJetDo;
   float h_stvf_SoftJetResoUp;
   float h_stvf_SoftJetResoDo;
   float h_metx;
   float h_mety;  
   float h_metphi;
   float h_mt;
   float h_pt;
   float h_mll;

   float h_refinal_met;
   float h_refinal_metphi;
   float h_refinal_sumet;
   float h_refinal_etx;
   float h_refinal_ety;
   float h_refinal_metphi_C;
   float h_refinal_sumet_C;
   float h_refinal_etx_C;
   float h_refinal_ety_C;
   float h_refinal_metphi_E;
   float h_refinal_sumet_E;
   float h_refinal_etx_E;
   float h_refinal_ety_E;
   float h_refinal_metphi_F;
   float h_refinal_sumet_F;
   float h_refinal_etx_F;
   float h_refinal_ety_F;

   float h_track_met;
   float h_track_metphi;
   float h_track_sumet;
   float h_track_etx;
   float h_track_ety;
   float h_track_metphi_C;
   float h_track_sumet_C;
   float h_track_etx_C;
   float h_track_ety_C;
   float h_track_metphi_E;
   float h_track_sumet_E;
   float h_track_etx_E;
   float h_track_ety_E;
   float h_track_metphi_F;
   float h_track_sumet_F;
   float h_track_etx_F;
   float h_track_ety_F;

   float h_refinal_stvf_met;
   float h_refinal_stvf_metphi;
   float h_refinal_stvf_sumet;
   float h_refinal_stvf_etx;
   float h_refinal_stvf_ety;
   float h_refinal_stvf_metphi_C;
   float h_refinal_stvf_sumet_C;
   float h_refinal_stvf_etx_C;
   float h_refinal_stvf_ety_C;
   float h_refinal_stvf_metphi_E;
   float h_refinal_stvf_sumet_E;
   float h_refinal_stvf_etx_E;
   float h_refinal_stvf_ety_E;
   float h_refinal_stvf_metphi_F;
   float h_refinal_stvf_sumet_F;
   float h_refinal_stvf_etx_F;
   float h_refinal_stvf_ety_F;

   float h_refjet_met;
   float h_refjet_metphi;
   float h_refjet_sumet;
   float h_refjet_etx;
   float h_refjet_ety;
   float h_refjet_metphi_C;
   float h_refjet_sumet_C;
   float h_refjet_etx_C;
   float h_refjet_ety_C;
   float h_refjet_metphi_E;
   float h_refjet_sumet_E;
   float h_refjet_etx_E;
   float h_refjet_ety_E;
   float h_refjet_metphi_F;
   float h_refjet_sumet_F;
   float h_refjet_etx_F;
   float h_refjet_ety_F;

   float h_cellout_eflow_met;
   float h_cellout_eflow_metphi;
   float h_cellout_eflow_sumet;
   float h_cellout_eflow_etx;
   float h_cellout_eflow_ety;
   float h_cellout_eflow_metphi_C;
   float h_cellout_eflow_sumet_C;
   float h_cellout_eflow_etx_C;
   float h_cellout_eflow_ety_C;
   float h_cellout_eflow_metphi_E;
   float h_cellout_eflow_sumet_E;
   float h_cellout_eflow_etx_E;
   float h_cellout_eflow_ety_E;
   float h_cellout_eflow_metphi_F;
   float h_cellout_eflow_sumet_F;
   float h_cellout_eflow_etx_F;
   float h_cellout_eflow_ety_F;

   float h_softjets_met;
   float h_softjets_metphi;
   float h_softjets_sumet;
   float h_softjets_etx;
   float h_softjets_ety;
   float h_softjets_metphi_C;
   float h_softjets_sumet_C;
   float h_softjets_etx_C;
   float h_softjets_ety_C;
   float h_softjets_metphi_E;
   float h_softjets_sumet_E;
   float h_softjets_etx_E;
   float h_softjets_ety_E;
   float h_softjets_metphi_F;
   float h_softjets_sumet_F;
   float h_softjets_etx_F;
   float h_softjets_ety_F;

   float h_truth_etx;
   float h_truth_ety;
   float h_truth_phi;
   float h_truth_et;
   float h_truth_sumet;

   float h_HforRej;
   float h_weight;  
   float h_weight_1;  
   float h_weight_2;  
   float h_weight_3;  
   float h_weight_4;  
   float h_Pweight;  
   float h_jetclean;  
   float h_metclean;  
   Int_t h_NGoodVtx;
   Int_t h_pass_lepton_veto;
   Int_t h_pass_jet_veto;
   Int_t h_pass_grl;
   Int_t h_njet;
   Int_t h_nbjet;
   Int_t h_nhjet;
   float h_jjdr;

bool kIsData = true;
bool kIsCutFlow =true;
bool kIsSave =false;
bool kIsReverse = false;
bool kIsSimple = false;
bool kMETClean = true;

TString Gen_Option;
string MC_runNumber;
Int_t tmp_runNum;

TRandom3 *m_Random = new TRandom3();

TH1D *h_cutflow_eg_num;
TH1D *h_cutflow_eg_num_1;
TH1D *h_cutflow_eg_num_2;

TH1D *h_cutflow_eg_wei;
TH1D *h_cutflow_eg_wei_1;
TH1D *h_cutflow_eg_wei_2;

TH1D *h_cutflow_eg_elec;
TH1D *h_cutflow_eg_elec_1;
TH1D *h_cutflow_eg_elec_2;


TH1D *h_cutflow_mu_num;
TH1D *h_cutflow_mu_num_1;
TH1D *h_cutflow_mu_num_2;

TH1D *h_cutflow_mu_wei;
TH1D *h_cutflow_mu_wei_1;
TH1D *h_cutflow_mu_wei_2;

TH1D *h_cutflow_mu_muon;
TH1D *h_cutflow_mu_muon_1;
TH1D *h_cutflow_mu_muon_2;

TH1D *h_cutflow_jet;
TH1D *h_cutflow_jet_1;
TH1D *h_cutflow_jet_2;



Int_t nlooseelec;
Int_t nloosemuon;
Int_t nloosejet;
Int_t nbadjet;

physics::physics(TTree* _tree_, const char* _filename_,const char* _option_){
SetOption(_option_);
SetOutputFile(_filename_);

Init(_tree_);
}

physics::~physics(){
        //Terminate();
        if(!fChain) return ;
        delete fChain->GetCurrentFile();
}

bool physics::SetOutputFile(const char* _filename_){
        TString _option = GetOption();
        Gen_Option = _option;
        TString outName(_filename_);
        TString outRooName = outName +".root";
        TString outTxtName = outName+".txt";
        if(_option.Contains("MC")){cout<<"===Not data==="<<endl; kIsData=false;}
        if(_option.Contains("Scale")){cout<<"===start to apply all scaling/smearing==="<<endl; kIsCutFlow=false;}
        if(_option.Contains("Save")){cout<<"===save small ntuples==="<<endl; kIsSave=true;}
        if(_option.Contains("Simple")){cout<<"===save small ntuples (only signal objet) ==="<<endl; kIsSimple=true;}
        if(_option.Contains("Reverse")){cout<<"===Reverse cuts for Leptons==="<<endl; kIsReverse=true;}
        if(_option.Contains("UPDATE")) fFile=new TFile(outRooName,"update");
        else fFile = new TFile(outRooName,"recreate");
        TDirectory *savedir = gDirectory;
        //if (fFile && fFile->IsZombie()) SafeDelete(fFile);
        savedir->cd();
        if (!fFile) {
                cout<<"Cannot create"<<fFile->GetName()<<" "<<endl;
                return false;
        }
        fOut.open(outTxtName);
        if(fOut.is_open()){
                cout<<outTxtName<<" is created"<<endl;
        }else{
                cout<<"Fail opening: "<< outTxtName<<endl;
        }
        return true;
}

MultijetJESUncertaintyProvider myJES("MultijetJES_Preliminary.config","JESUncertainty2012_FirstData.config","AntiKt4TopoEM","Pythia8");

JERProvider myJER("AntiKt4TopoJES","Truth","JERProviderPlots.root");

vector< pair<int, float> > count_egamma;
vector< pair<int, float> > count_muon;

pair<string, string> name("Zahid","Ghadialy"); 
pair<int, float> count_pair(0,0);


  Int_t ic_all(0), ic_author(0), ic_et(0),  ic_d0(0), ic_tight(0), ic_eta(0),ic_ptcone(0), ic_etcone(0), ic_oq(0), ic_or(0), ic_or2(0), ic_allcuts(0);
  Int_t ic_veto_all(0), ic_veto_author(0), ic_veto_et(0),  ic_veto_d0(0), ic_veto_tight(0), ic_veto_eta(0),ic_veto_ptcone(0), ic_veto_etcone(0), ic_veto_oq(0), ic_veto_or(0), ic_veto_or2(0), ic_veto_allcuts(0);


  Int_t icm_veto_all(0), icm_veto_tight(0), icm_veto_trtL(0), icm_veto_trtH(0), icm_veto_d0(0), icm_veto_z0(0), icm_veto_blayer(0), icm_veto_pixel(0), icm_veto_sct(0), icm_veto_PixSCThole(0), icm_veto_vetopt(0), icm_veto_pt(0), icm_veto_eta(0), icm_veto_ptcone(0), icm_veto_etcone(0), icm_veto_or(0),icm_veto_allcut(0);
  Int_t icm_all(0), icm_tight(0), icm_trtL(0), icm_trtH(0), icm_d0(0), icm_z0(0), icm_blayer(0), icm_pixel(0), icm_sct(0), icm_PixSCThole(0), icm_vetopt(0), icm_pt(0), icm_eta(0), icm_ptcone(0), icm_etcone(0), icm_or(0),icm_allcut(0);


  Int_t icj_all(0), icj_e(0), icj_notbadloose(0), icj_notbad(0), icj_notugly(0), icj_pt(0), icj_eta(0), icj_jvf(0), icj_or(0), icj_allcuts(0);
  Int_t icj_veto_all(0), icj_veto_e(0), icj_veto_notbadloose(0), icj_veto_notbad(0), icj_veto_notugly(0), icj_veto_pt(0), icj_veto_eta(0), icj_veto_jvf(0), icj_veto_or(0), icj_veto_allcuts(0);

 //firstname, lastname

  //Analysis::CalibrationDataInterfaceROOT calib("MV1", "BTagCalibration.env");
  Analysis::CalibrationDataInterfaceROOT *calib; 
  Analysis::CalibrationDataVariables ajet;
  Analysis::Uncertainty uncertainty = Analysis::Total;


void physics::Begin(TTree * /*tree*/)
{
   // The Begin() function is called at the start of the query.
   // When running with PROOF Begin() is only called on the client.
   // The tree argument is deprecated (on PROOF 0 is passed).

   TString option = GetOption();

}

void physics::SlaveBegin(TTree * /*tree*/)
{
 gROOT->ProcessLine("#include <vector>"); 

bookBranch();

   // The SlaveBegin() function is called after the Begin() function.
   // When running with PROOF SlaveBegin() is called on each slave server.
   // The tree argument is deprecated (on PROOF 0 is passed).

  string custName = name.first+" "+name.second;
  float test = count_pair.first + count_pair.second;

//start to get good run list

        TGoodRunsListReader* grlR = new TGoodRunsListReader();
        //string sname_full = "data11_7TeV.periodAllYear_DetStatus-v36-pro10_CoolRunQuery-00-04-08_WZjets_allchannels.xml";
        //string sname_full = "data12_8TeV.periodAllYear_DetStatus-v45-pro13_CoolRunQuery-00-04-08_All_Good.xml";
        string sname_full = "data12_8TeV.periodAllYear_DetStatus-v50-pro13-04_CoolRunQuery-00-04-08_All_Good.xml";
        grlR->SetXMLFile(sname_full.c_str());grlR->Interpret();
        grl_full = grlR->GetMergedGoodRunsList();
//finish get good run list

for(int i=0; i<20; i++){
count_egamma.push_back(count_pair);
count_muon.push_back(count_pair);
}

h_cutflow_eg_num = new TH1D("cutflow_eg_num","cutflow_eg_num",40,0.5,40.5); 
h_cutflow_eg_num_1 = new TH1D("cutflow_eg_num_1","cutflow_eg_num_1",40,0.5,40.5); 
h_cutflow_eg_num_2 = new TH1D("cutflow_eg_num_2","cutflow_eg_num_2",40,0.5,40.5); 

h_cutflow_eg_wei = new TH1D("cutflow_eg_wei","cutflow_eg_wei",40,0.5,40.5); 
h_cutflow_eg_wei_1 = new TH1D("cutflow_eg_wei_1","cutflow_eg_wei_1",40,0.5,40.5); 
h_cutflow_eg_wei_2 = new TH1D("cutflow_eg_wei_2","cutflow_eg_wei_2",40,0.5,40.5); 

h_cutflow_eg_elec = new TH1D("cutflow_eg_elec","cutflow_eg_elec",40,0.5,40.5);
h_cutflow_eg_elec_1 = new TH1D("cutflow_eg_elec_1","cutflow_eg_elec_1",40,0.5,40.5);
h_cutflow_eg_elec_2 = new TH1D("cutflow_eg_elec_2","cutflow_eg_elec_2",40,0.5,40.5);


h_cutflow_mu_num = new TH1D("cutflow_mu_num","cutflow_mu_num",40,0.5,40.5);
h_cutflow_mu_num_1 = new TH1D("cutflow_mu_num_1","cutflow_mu_num_1",40,0.5,40.5);
h_cutflow_mu_num_2 = new TH1D("cutflow_mu_num_2","cutflow_mu_num_2",40,0.5,40.5);

h_cutflow_mu_wei = new TH1D("cutflow_mu_wei","cutflow_mu_wei",40,0.5,40.5);
h_cutflow_mu_wei_1 = new TH1D("cutflow_mu_wei_1","cutflow_mu_wei_1",40,0.5,40.5);
h_cutflow_mu_wei_2 = new TH1D("cutflow_mu_wei_2","cutflow_mu_wei_2",40,0.5,40.5);

h_cutflow_mu_muon = new TH1D("cutflow_mu_muon","cutflow_mu_muon",40,0.5,40.5);
h_cutflow_mu_muon_1 = new TH1D("cutflow_mu_muon_1","cutflow_mu_muon_1",40,0.5,40.5);
h_cutflow_mu_muon_2 = new TH1D("cutflow_mu_muon_2","cutflow_mu_muon_2",40,0.5,40.5);


h_cutflow_jet = new TH1D("cutflow_jet","cutflow_jet",40,0.5,40.5);
h_cutflow_jet_1 = new TH1D("cutflow_jet_1","cutflow_jet_1",40,0.5,40.5);
h_cutflow_jet_2 = new TH1D("cutflow_jet_2","cutflow_jet_2",40,0.5,40.5);


egSF = new egammaSFclass();

   TString option = Gen_Option;
cout<<"In initial : the option is "<< option <<endl;
if(option.Contains("GenPile")){
//Extended pileup weight
m_pileupTool = new Root::TPileupReweighting("MyReweighting");
m_pileupTool->UsePeriodConfig("MC12a"); //for MC11b change the string to "MC11b"
m_pileupTool->initialize();
}
else if(option.Contains("PileUp")){
cout<<"before initialize"<<endl;
m_pileupTool = new Root::TPileupReweighting("MyReweighting");
m_pileupTool->AddConfigFile("MyReweighting.prw.root");
m_pileupTool->SetDataScaleFactors(0.9);
m_pileupTool->AddLumiCalcFile("ilumicalc_histograms_None_200841-207931.root"); 
m_pileupTool->SetUnrepresentedDataAction(2);
m_pileupTool->initialize();
cout<<"after initialize"<<endl;
cout<<"before initialize"<<endl;
m_pileupTool_1 = new Root::TPileupReweighting("MyReweighting_1");
m_pileupTool_1 ->AddConfigFile("MyReweighting.prw.root");
m_pileupTool_1 ->SetDataScaleFactors(1.0);
m_pileupTool_1 ->AddLumiCalcFile("ilumicalc_histograms_None_200841-207931.root");
m_pileupTool_1 ->SetUnrepresentedDataAction(2);
m_pileupTool_1 ->initialize();
cout<<"after initialize"<<endl;
cout<<"before initialize"<<endl;
m_pileupTool_2 = new Root::TPileupReweighting("MyReweighting_2");
m_pileupTool_2 ->AddConfigFile("MyReweighting.prw.root");
m_pileupTool_2 ->SetDataScaleFactors(0.8);
m_pileupTool_2 ->AddLumiCalcFile("ilumicalc_histograms_None_200841-207931.root");
m_pileupTool_2 ->SetUnrepresentedDataAction(2);
m_pileupTool_2 ->initialize();
cout<<"after initialize"<<endl;
m_pileupTool_3 = new Root::TPileupReweighting("MyReweighting_3");
m_pileupTool_3 ->AddConfigFile("MyReweighting.prw.root");
m_pileupTool_3 ->SetDataScaleFactors(0.94);
m_pileupTool_3 ->AddLumiCalcFile("ilumicalc_histograms_None_200841-207931.root");
m_pileupTool_3 ->SetUnrepresentedDataAction(2);
m_pileupTool_3 ->initialize();
cout<<"after initialize"<<endl;
m_pileupTool_4 = new Root::TPileupReweighting("MyReweighting_4");
m_pileupTool_4 ->AddConfigFile("MyReweighting.prw.root");
m_pileupTool_4 ->SetDataScaleFactors(0.86);
m_pileupTool_4 ->AddLumiCalcFile("ilumicalc_histograms_None_200841-207931.root");
m_pileupTool_4 ->SetUnrepresentedDataAction(2);
m_pileupTool_4 ->initialize();
cout<<"after initialize"<<endl;
}
//Extended pileup weight


  //myJES.includeFlavorComposition(false);
  //myJES.init();
  myJER.init();

    eRescale.useDefaultCalibConstants("2012");

   //Apply JER
  my_JetSmearing_NEW = new JetSmearingTool();
  ajet.jetAuthor = "AntiKt4TopoEM";
  calib = new Analysis::CalibrationDataInterfaceROOT("MV1", "BTagCalibration_2012.env");

   //Muon correction

   string smear_dir = "MuonMoment_share/";
   mcp_smear_muid = new MuonSmear::SmearingClass("Data12","muid","pT","Rel17.2_preliminary",smear_dir); 
   mcp_smear_muid->UseScale(1); 
   mcp_smear_muid->UseImprovedCombine(); 


   m_MCPsf = new Analysis::AnalysisMuonConfigurableScaleFactors("MuonEffi_share/","Muid_CB_2012_SF.txt","MeV",Analysis::AnalysisMuonConfigurableScaleFactors::AverageOverRuns);
   m_MCPsf->Initialise();


  m_leptonSF = new LeptonTriggerSF(2012, "TrigMuon_share", "muon_trigger_sf_2012.root");
/*
  //Muon Trigger matching
    triggerNavigationVariables = new TriggerNavigationVariables();
    triggerNavigationVariables->set_trig_DB_SMK(trig_DB_SMK);
    triggerNavigationVariables->set_trig_Nav_n(trig_Nav_n);
    triggerNavigationVariables->set_trig_Nav_chain_ChainId(trig_Nav_chain_ChainId);
    triggerNavigationVariables->set_trig_Nav_chain_RoIType(trig_Nav_chain_RoIType);
    triggerNavigationVariables->set_trig_Nav_chain_RoIIndex(trig_Nav_chain_RoIIndex);

    // electron 
    triggerNavigationVariables->set_trig_RoI_EF_e_egammaContainer_egamma_Electrons(trig_RoI_EF_e_egammaContainer_egamma_Electrons);
    triggerNavigationVariables->set_trig_RoI_EF_e_egammaContainer_egamma_ElectronsStatus(trig_RoI_EF_e_egammaContainer_egamma_ElectronsStatus);
    triggerNavigationVariables->set_trig_EF_el_n(trig_EF_el_n);
    triggerNavigationVariables->set_trig_EF_el_eta(trig_EF_el_eta);
    triggerNavigationVariables->set_trig_EF_el_phi(trig_EF_el_phi);

    // muon 
    triggerNavigationVariables->set_trig_RoI_EF_mu_Muon_ROI(trig_RoI_EF_mu_Muon_ROI);
    triggerNavigationVariables->set_trig_RoI_EF_mu_TrigMuonEFInfoContainer(trig_RoI_EF_mu_TrigMuonEFInfoContainer);
    triggerNavigationVariables->set_trig_RoI_EF_mu_TrigMuonEFInfoContainerStatus(trig_RoI_EF_mu_TrigMuonEFInfoContainerStatus);
    triggerNavigationVariables->set_trig_RoI_L2_mu_CombinedMuonFeature(trig_RoI_L2_mu_CombinedMuonFeature);
    triggerNavigationVariables->set_trig_RoI_L2_mu_CombinedMuonFeatureStatus(trig_RoI_L2_mu_CombinedMuonFeatureStatus);
    triggerNavigationVariables->set_trig_RoI_L2_mu_MuonFeature(trig_RoI_L2_mu_MuonFeature);
    triggerNavigationVariables->set_trig_RoI_L2_mu_Muon_ROI(trig_RoI_L2_mu_Muon_ROI);
    triggerNavigationVariables->set_trig_EF_trigmuonef_track_CB_pt(trig_EF_trigmuonef_track_CB_pt);
    triggerNavigationVariables->set_trig_EF_trigmuonef_track_CB_eta(trig_EF_trigmuonef_track_CB_eta);
    triggerNavigationVariables->set_trig_EF_trigmuonef_track_CB_phi(trig_EF_trigmuonef_track_CB_phi);
    triggerNavigationVariables->set_trig_EF_trigmuonef_track_SA_pt(trig_EF_trigmuonef_track_SA_pt);
    triggerNavigationVariables->set_trig_EF_trigmuonef_track_SA_eta(trig_EF_trigmuonef_track_SA_eta);
    triggerNavigationVariables->set_trig_EF_trigmuonef_track_SA_phi(trig_EF_trigmuonef_track_SA_phi);
    triggerNavigationVariables->set_trig_EF_trigmugirl_track_CB_pt(trig_EF_trigmugirl_track_CB_pt);
    triggerNavigationVariables->set_trig_EF_trigmugirl_track_CB_eta(trig_EF_trigmugirl_track_CB_eta);
    triggerNavigationVariables->set_trig_EF_trigmugirl_track_CB_phi(trig_EF_trigmugirl_track_CB_phi);
    triggerNavigationVariables->set_trig_L2_combmuonfeature_eta(trig_L2_combmuonfeature_eta);
    triggerNavigationVariables->set_trig_L2_combmuonfeature_phi(trig_L2_combmuonfeature_phi);
    triggerNavigationVariables->set_trig_L2_muonfeature_eta(trig_L2_muonfeature_eta);
    triggerNavigationVariables->set_trig_L2_muonfeature_phi(trig_L2_muonfeature_phi);
    triggerNavigationVariables->set_trig_L1_mu_eta(trig_L1_mu_eta);
    triggerNavigationVariables->set_trig_L1_mu_phi(trig_L1_mu_phi);
    triggerNavigationVariables->set_trig_L1_mu_thrName(trig_L1_mu_thrName);
    triggerNavigationVariables->set_trig_RoI_EF_mu_TrigMuonEFIsolationContainer(trig_RoI_EF_mu_TrigMuonEFIsolationContainer); // for 2012 isolated trigger
    triggerNavigationVariables->set_trig_RoI_EF_mu_TrigMuonEFIsolationContainerStatus(trig_RoI_EF_mu_TrigMuonEFIsolationContainerStatus); // for 2012 isolated trigger
    triggerNavigationVariables->set_trig_EF_trigmuonef_EF_mu15(trig_EF_trigmuonef_EF_mu15);  // for ntuple made with TriggerMenuAnalysis-00-02-86
    triggerNavigationVariables->set_trig_EF_trigmuonef_EF_mu24i_tight(trig_EF_trigmuonef_EF_mu24i_tight);  // for ntuple made with TriggerMenuAnalysis-00-02-86
    triggerNavigationVariables->set_trig_EF_trigmuonef_EF_mu36_tight(trig_EF_trigmuonef_EF_mu36_tight); // for ntuple made with TriggerMenuAnalysis-00-02-86

    if (not triggerNavigationVariables->isValid()) {
      std::cerr << "VARIABLES NOT CORRECTLY SET\n";
    }
    MuonTriggerMatching *muonTriggerMatchTool = new MuonTriggerMatching(triggerNavigationVariables);
    ElectronTriggerMatching *electronTriggerMatchTool = new ElectronTriggerMatching(triggerNavigationVariables);
*/
}

Bool_t physics::Process(Long64_t entry)
{

clearBranch();
   TString _option_general = Gen_Option;



if(!kIsData){
b_trig_L1_TAV->GetEntry( entry );
   // Check if bit 17 is turned on:
   if( ! ( ( ( *trig_L1_TAV )[ 0 ] >> 17 ) & 0x1 ) ) {
      return kTRUE;
   }
}


  count_number = count_number+1;
   b_RunNumber->GetEntry(entry);   //!

int myRunNumber = RunNumber;
if(myRunNumber < 200804) myRunNumber = 204158;// attention here! Only for 1 signal which have very old run number; 


double event_weight = 1.0;
   if(_option_general.Contains("GenPile") || _option_general.Contains("PileUp")){
   b_averageIntPerXing->GetEntry(entry);   //!
   b_mc_channel_number->GetEntry(entry);   //!
   b_mcevt_weight->GetEntry(entry);   //!

if(mcevt_weight->size()>0){
vector<double> tmp_weight = mcevt_weight->at(0);
if(tmp_weight.size()>0)
event_weight = tmp_weight.at(0);
   }

}

 if(count_number%10000==0)cout<<"processed "<<count_number<<" events"<<endl;

      if (curr_file!=fChain->GetCurrentFile()->GetName())
        {
          cout<<"New File: "<<fChain->GetCurrentFile()->GetName()<<endl;
          curr_file=fChain->GetCurrentFile()->GetName();
        }

float Pileup_event_weight=1.0;
float Pileup_event_weight_1=1.0;
float Pileup_event_weight_2=1.0;
float Pileup_event_weight_3=1.0;
float Pileup_event_weight_4=1.0;
if(!kIsData){
if(_option_general.Contains("GenPile")){
Int_t runNum = RunNumber;
Int_t mc_channel = mc_channel_number;
ostringstream oss1; oss1 << mc_channel; string mystr1; mystr1=oss1.str();  
MC_runNumber = mystr1;

float mc_weight = 1.0;
//cout<<"mc channel number : "<< mc_channel <<"    check the string "<<MC_runNumber<<endl;  
if(mcevt_weight->size()>0){
vector<double> tmp_weight = mcevt_weight->at(0);
if(tmp_weight.size()>0){
mc_weight = tmp_weight.at(0);
//cout<<"the weight is "<<mc_weight<<"    "<<mcevt_weight->at(0).at(0)<<endl;
}
}

if(tmp_runNum != runNum){
tmp_runNum = runNum;
//cout<<"run number is "<<tmp_runNum<<endl;
}
 
float ave_InterP = averageIntPerXing;
m_pileupTool->Fill(runNum,mc_channel,mc_weight,ave_InterP);
return kTRUE;
}//Generate MC config file
else if(_option_general.Contains("PileUp")){
Int_t tmp_channel = 195847;
Pileup_event_weight = event_weight * (m_pileupTool->GetCombinedWeight(RunNumber,tmp_channel,averageIntPerXing));
Pileup_event_weight_1 = event_weight * (m_pileupTool_1->GetCombinedWeight(RunNumber,tmp_channel,averageIntPerXing));
Pileup_event_weight_2 = event_weight * (m_pileupTool_2->GetCombinedWeight(RunNumber,tmp_channel,averageIntPerXing));
Pileup_event_weight_3 = event_weight * (m_pileupTool_3->GetCombinedWeight(RunNumber,tmp_channel,averageIntPerXing));
Pileup_event_weight_4 = event_weight * (m_pileupTool_4->GetCombinedWeight(RunNumber,tmp_channel,averageIntPerXing));
}
}

int myChannel(0);
if(!kIsData){
b_mc_channel_number->GetEntry(entry);
myChannel = mc_channel_number;
}


 count_egamma.at(0).first ++;
 count_muon.at(0).first ++;
//Fill cutflow  
 h_cutflow_eg_num->Fill(1); 
 h_cutflow_eg_wei->Fill(1,Pileup_event_weight); 
 h_cutflow_mu_num->Fill(1);
 h_cutflow_mu_wei->Fill(1,Pileup_event_weight);

 h_cutflow_mu_num_1->Fill(1);

//hfor rejection
bool HForRej = true;
if(!kIsData){
b_top_hfor_type->GetEntry(entry);
if(top_hfor_type==4)HForRej = false;
}

//Fill cutflow
if(HForRej){
 h_cutflow_eg_num->Fill(2);
 h_cutflow_eg_wei->Fill(2,Pileup_event_weight);
 h_cutflow_mu_num->Fill(2);
 h_cutflow_mu_wei->Fill(2,Pileup_event_weight);

}

b_lbn->GetEntry(entry);
h_pass_grl=0;
if(!kIsData){ h_pass_grl=1;}
else if(kIsData && grl_full.HasRunLumiBlock(RunNumber,lbn)){
 count_egamma.at(1).first ++;
 count_muon.at(1).first ++;
 h_pass_grl = 1;
}

if(!kIsData && HForRej){
 count_egamma.at(1).first ++;
 count_muon.at(1).first ++;
}

//Fill cutflow
if(HForRej && h_pass_grl){
 h_cutflow_eg_num->Fill(3);
 h_cutflow_eg_wei->Fill(3,Pileup_event_weight);
 h_cutflow_mu_num->Fill(3);
 h_cutflow_mu_wei->Fill(3,Pileup_event_weight);
}
Set_Branch(entry);


//get electron index
      vector<container> elec_index_met;
      vector<container> muon_index_met;
      vector<container> jet_index_met;

      vector<container> elec_index_veto_NOR;
      vector<container> elec_index_veto;
      vector<container> muon_index_veto;
      vector<container> muon_index_veto_nocalo;
      vector<container> jet_index_veto;

      vector<container> elec_index_save;
      vector<container> muon_index_save;
      vector<container> muon_index_save_nocalo;
      vector<container> jet_index_save;

      vector<container> dummy_vector;

elec_index_met.clear();
muon_index_met.clear();
jet_index_met.clear();

elec_index_veto_NOR.clear();
elec_index_veto.clear();
muon_index_veto.clear();
muon_index_veto_nocalo.clear();
jet_index_veto.clear();

elec_index_save.clear();
muon_index_save.clear();
muon_index_save_nocalo.clear();
jet_index_save.clear();

dummy_vector.clear();

bool Pass_jetclean=true;
     kMETClean = true; 

TString option = "none";
TString option_ele_removal = "RemoveOVLJRemoveOVLM";
TString option_ele_veto_removal = "vetoRemoveOVLJRemoveOVLM";
TString option_ele_veto_NOremoval = "vetoNoRemove";
TString option2 = "veto";
TString option3 = "noncalo";
TString option_save = "saveRemoveOVLJRemoveOVLM";

//Get loose electrons without remove overlap 
elec_index_veto_NOR = get_electron_met(myRunNumber, kIsData, option_ele_veto_NOremoval ,dummy_vector,dummy_vector); 

//Get loose/signal jets
jet_index_met = get_jet_met(myRunNumber, kIsData, option, elec_index_veto_NOR);
nloosejet=0;
nbadjet=0;
jet_index_veto = get_jet_met(myRunNumber, kIsData, option2, elec_index_veto_NOR);
if(nbadjet>0) Pass_jetclean=false;

//Get loose/signal muons 
nloosemuon=0;
muon_index_veto_nocalo = get_muon_met(myRunNumber, kIsData, option2, jet_index_veto);
muon_index_veto = get_calomuon_met(myRunNumber, kIsData, option2, jet_index_veto,muon_index_veto_nocalo);
muon_index_met=get_muon_met(myRunNumber, kIsData, option, jet_index_veto);

//Get loose/signal elecs
elec_index_met=get_electron_met(myRunNumber, kIsData, option_ele_removal, jet_index_veto,muon_index_veto);
nlooseelec=0;
elec_index_veto = get_electron_met(myRunNumber, kIsData, option_ele_veto_removal, jet_index_veto,muon_index_veto); 

//Saving objects for later use
elec_index_save = get_electron_met(myRunNumber, kIsData, option_save, jet_index_veto,muon_index_veto);
muon_index_save_nocalo = get_muon_met(myRunNumber, kIsData, option_save, jet_index_veto);
muon_index_save = get_calomuon_met(myRunNumber, kIsData, option_save, jet_index_veto,muon_index_save_nocalo);
jet_index_save = get_jet_met(myRunNumber, kIsData, option_save, elec_index_veto_NOR);




int N_muonL = muon_index_veto.size();
int N_elecL = elec_index_veto.size(); 


int N_muon = muon_index_met.size();
int N_elec = elec_index_met.size(); 

vector<TLorentzVector> trig_muons;
vector<TLorentzVector> trig_elecs;
for(int i=0; i< N_muon; i++) trig_muons.push_back(muon_index_met.at(i).tlv);
for(int i=0; i< N_elec; i++) trig_elecs.push_back(elec_index_met.at(i).tlv);

pair<double,double> trig_SF(1,0);

if(!kIsData){
trig_SF = m_leptonSF->GetTriggerSF(myRunNumber,true, trig_muons, combined , trig_elecs, tightpp, 0);
}

bool pass_lepton_veto = true;
if(N_elecL + N_muonL >= 3)pass_lepton_veto=false;
else if (N_muon + N_elec >= 2 ) pass_lepton_veto=false;
else if(N_muon ==1  && N_elecL==1){
 if(elec_index_veto[0].pt > 20000) pass_lepton_veto=false;
 else if (elec_index_veto[0].charge * muon_index_met[0].charge == -1) pass_lepton_veto=false;
}
else if(N_elec ==1  && N_muonL==1){
 if(muon_index_veto[0].pt > 20000) pass_lepton_veto=false;
 else if (muon_index_veto[0].charge * elec_index_met[0].charge == -1) pass_lepton_veto=false;
} 
else if(N_elecL==2){
 if(elec_index_veto[0].pt > 20000 && elec_index_veto[1].pt > 20000 ) pass_lepton_veto=false;
 else if (elec_index_veto[0].charge * elec_index_veto[1].charge == -1) pass_lepton_veto=false;
}
else if(N_muonL==2){
 if(muon_index_veto[0].pt > 20000 && muon_index_veto[1].pt > 20000 ) pass_lepton_veto=false;
 else if (muon_index_veto[0].charge * muon_index_veto[1].charge == -1) pass_lepton_veto=false;
}


bool pass_lar_error = true;
if(larError>1)pass_lar_error=false;

//check good vertex
int Cut_NumTrackPV = 3;
int N_Good_Vtx = 0;
int First_Good_Vtx(0);

    if( (*vxp_nTracks)[0] >= Cut_NumTrackPV ) N_Good_Vtx++;


bool Good_Vtx = false;
if(N_Good_Vtx>0)Good_Vtx = true;

//Fill cutflow
if(HForRej && h_pass_grl && Good_Vtx){
 h_cutflow_eg_num->Fill(4);
 h_cutflow_eg_wei->Fill(4,Pileup_event_weight);
}

//MET cleaning (require no bad jet)
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean){
 h_cutflow_eg_num->Fill(5);
 h_cutflow_eg_wei->Fill(5,Pileup_event_weight);
}

//LAr error
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error){
 h_cutflow_eg_num->Fill(6);
 h_cutflow_eg_wei->Fill(6,Pileup_event_weight);
}

//Jet clean (not require for 2012)
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean){
 h_cutflow_eg_num->Fill(7);
 h_cutflow_eg_wei->Fill(7,Pileup_event_weight);
}



bool Nlepton_lr_1 = true;
if(N_muonL+N_elecL<1) Nlepton_lr_1 = false;


bool pass_jet_veto = false;
if(jet_index_veto.size()<=2) pass_jet_veto=true; 


//triggers
bool egamma_trigger = false;
bool muon_trigger = false;

bool tmp_eg_trig =false;
bool tmp_mu_trig = false;

   if(EF_e24vhi_medium1 ||EF_e60_medium1)tmp_eg_trig=true;
   if(EF_mu24i_tight || EF_mu36_tight)tmp_mu_trig=true;


if(tmp_eg_trig) egamma_trigger = true;
else if(tmp_mu_trig) muon_trigger = true;

//at least one good lepton
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1){
 h_cutflow_eg_num->Fill(8);
 h_cutflow_eg_wei->Fill(8,Pileup_event_weight);
}


//1 selected e or mu
bool Only_1lepton = false;
if(N_elec + N_muon>=1)Only_1lepton=true;//In the cutflow, they change to >=1 signal lepton 

//1 WH signal lepton
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton){
 h_cutflow_eg_num->Fill(9);
 h_cutflow_eg_wei->Fill(9,Pileup_event_weight);
}

//Trigger
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && egamma_trigger){
 h_cutflow_eg_num->Fill(10);
 h_cutflow_eg_wei->Fill(10,Pileup_event_weight);
}
else if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && muon_trigger){
 h_cutflow_mu_num->Fill(10);
 h_cutflow_mu_wei->Fill(10,Pileup_event_weight);
}


//Lepton veto
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && egamma_trigger && pass_lepton_veto){
 h_cutflow_eg_num->Fill(11);
 h_cutflow_eg_wei->Fill(11,Pileup_event_weight);
}
else if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && muon_trigger && pass_lepton_veto){
 h_cutflow_mu_num->Fill(11);
 h_cutflow_mu_wei->Fill(11,Pileup_event_weight);
}


float sysRefinal(0),SoftJetUp(0),SoftJetDo(0),CellOutUp(0),CellOutDo(0),SoftJetResoUp(0),SoftJetResoDo(0);
float sysRefinal_stvf(0),SoftJetUp_stvf(0),SoftJetDo_stvf(0),CellOutUp_stvf(0),CellOutDo_stvf(0),SoftJetResoUp_stvf(0),SoftJetResoDo_stvf(0);

if(!kIsData){

  METUtility *metSys = new METUtility;
metSys->reset();
bool is2012 = true;
bool isSTVF = false;
 metSys->configMissingET(is2012, isSTVF);

 //metSys->setObjects("jets", jet_AntiKt4LCTopo_pt, jet_AntiKt4LCTopo_eta, jet_AntiKt4LCTopo_phi, jet_AntiKt4LCTopo_E, jet_AntiKt4LCTopo_MET_wet, jet_AntiKt4LCTopo_MET_wpx, jet_AntiKt4LCTopo_MET_wpy, jet_AntiKt4LCTopo_MET_statusWord);
 //metSys->setExtraJetParameters(jet_AntiKt4LCTopo_GCWJES, jet_AntiKt4LCTopo_m, jet_AntiKt4LCTopo_eta, jet_AntiKt4LCTopo_phi);

 metSys->setElectronParameters(el_pt, el_eta, el_phi, el_MET_wet, el_MET_wpx, el_MET_wpy, el_MET_statusWord);
 metSys->setPhotonParameters(ph_pt, ph_eta, ph_phi, ph_MET_wet, ph_MET_wpx, ph_MET_wpy, ph_MET_statusWord); 
 metSys->setTauParameters(tau_pt, tau_eta, tau_phi, tau_MET_wet, tau_MET_wpx, tau_MET_wpy, tau_MET_statusWord);

 metSys->setMuonParameters(mu_muid_pt, mu_muid_eta, mu_muid_phi, mu_muid_MET_wet, mu_muid_MET_wpx, mu_muid_MET_wpy, mu_muid_MET_statusWord);
 metSys->setExtraMuonParameters(mu_muid_pt, mu_muid_ms_theta, mu_muid_ms_phi,mu_muid_charge);

float MET_CellOut_Eflow_etx = MET_CellOut_Eflow_et * cos(MET_CellOut_Eflow_phi);
float MET_CellOut_Eflow_ety = MET_CellOut_Eflow_et * sin(MET_CellOut_Eflow_phi);

float MET_CellOut_etx = MET_CellOut_et * cos(MET_CellOut_phi);
float MET_CellOut_ety = MET_CellOut_et * sin(MET_CellOut_phi);

float MET_RefMuon_etx = MET_RefMuon_et *cos(MET_RefMuon_phi);
float MET_RefMuon_ety = MET_RefMuon_et *sin(MET_RefMuon_phi);

float MET_RefTau_etx = MET_RefTau_et *cos(MET_RefTau_phi);
float MET_RefTau_ety = MET_RefTau_et *sin(MET_RefTau_phi);


float MET_SoftJets_etx = MET_SoftJets_et *cos(MET_SoftJets_phi);
float MET_SoftJets_ety = MET_SoftJets_et *sin(MET_SoftJets_phi);

metSys->setMETTerm(METUtil::RefMuon, MET_RefMuon_etx, MET_RefMuon_ety, MET_RefMuon_sumet);
metSys->setMETTerm(METUtil::RefTau, MET_RefTau_etx, MET_RefTau_ety, MET_RefTau_sumet);
metSys->setMETTerm(METUtil::SoftJets, MET_SoftJets_etx, MET_SoftJets_ety, MET_SoftJets_sumet);
metSys->setMETTerm(METUtil::CellOutEflow, MET_CellOut_Eflow_etx, MET_CellOut_Eflow_ety, MET_CellOut_Eflow_sumet);

  sysRefinal = metSys->getMissingET(METUtil::RefFinal).et(); 
  SoftJetResoUp = metSys->getMissingET(METUtil::RefFinal,METUtil::ResoSoftTermsUp).et(); 
  SoftJetResoDo = metSys->getMissingET(METUtil::RefFinal,METUtil::ResoSoftTermsDown).et(); 
  SoftJetUp = metSys->getMissingET(METUtil::RefFinal,METUtil::ScaleSoftTermsUp).et();
  SoftJetDo = metSys->getMissingET(METUtil::RefFinal,METUtil::ScaleSoftTermsDown).et();

 delete metSys;

//for stvf
  METUtility *stvfSys = new METUtility;
stvfSys->reset();
 isSTVF = true;
 stvfSys->configMissingET(is2012, isSTVF);

 //stvfSys->setObjects("jets", jet_AntiKt4LCTopo_pt, jet_AntiKt4LCTopo_eta, jet_AntiKt4LCTopo_phi, jet_AntiKt4LCTopo_E, jet_AntiKt4LCTopo_MET_wet, jet_AntiKt4LCTopo_MET_wpx, jet_AntiKt4LCTopo_MET_wpy, jet_AntiKt4LCTopo_MET_statusWord);
 //stvfSys->setExtraJetParameters(jet_AntiKt4LCTopo_GCWJES, jet_AntiKt4LCTopo_m, jet_AntiKt4LCTopo_eta, jet_AntiKt4LCTopo_phi);

 stvfSys->setElectronParameters(el_pt, el_eta, el_phi, el_MET_wet, el_MET_wpx, el_MET_wpy, el_MET_statusWord);
 stvfSys->setPhotonParameters(ph_pt, ph_eta, ph_phi, ph_MET_wet, ph_MET_wpx, ph_MET_wpy, ph_MET_statusWord);
 stvfSys->setTauParameters(tau_pt, tau_eta, tau_phi, tau_MET_wet, tau_MET_wpx, tau_MET_wpy, tau_MET_statusWord);

 stvfSys->setMuonParameters(mu_muid_pt, mu_muid_eta, mu_muid_phi, mu_muid_MET_wet, mu_muid_MET_wpx, mu_muid_MET_wpy, mu_muid_MET_statusWord);
 stvfSys->setExtraMuonParameters(mu_muid_pt, mu_muid_ms_theta, mu_muid_ms_phi,mu_muid_charge);

stvfSys->setMETTerm(METUtil::RefMuon, MET_RefMuon_etx, MET_RefMuon_ety, MET_RefMuon_sumet);
stvfSys->setMETTerm(METUtil::RefTau, MET_RefTau_etx, MET_RefTau_ety, MET_RefTau_sumet);
//stvfSys->setMETTerm(METUtil::SoftJets, MET_SoftJets_etx, MET_SoftJets_ety, MET_SoftJets_sumet);
stvfSys->setMETTerm(METUtil::CellOutEflow, MET_CellOut_Eflow_etx, MET_CellOut_Eflow_ety, MET_CellOut_Eflow_sumet);

  sysRefinal_stvf = stvfSys->getMissingET(METUtil::RefFinal).et();
  SoftJetResoUp_stvf = stvfSys->getMissingET(METUtil::RefFinal,METUtil::ResoSoftTermsUp).et();
  SoftJetResoDo_stvf = stvfSys->getMissingET(METUtil::RefFinal,METUtil::ResoSoftTermsDown).et();
  SoftJetUp_stvf = stvfSys->getMissingET(METUtil::RefFinal,METUtil::ScaleSoftTermsUp).et();
  SoftJetDo_stvf = stvfSys->getMissingET(METUtil::RefFinal,METUtil::ScaleSoftTermsDown).et();

 delete stvfSys;



}


  double MET_new_etx = 0;
  double MET_new_ety = 0;
  double MET_new_et = 0;
  double MET_new_phi = 0;

//Use METRefinal at last

MET_new_et = MET_RefFinal_et; 
MET_new_phi = MET_RefFinal_phi;
MET_new_etx = MET_RefFinal_et * cos(MET_RefFinal_phi);
MET_new_ety = MET_RefFinal_et * sin(MET_RefFinal_phi);

/*
MET_new_et = MET_RefFinal_STVF_et;
MET_new_phi = MET_RefFinal_STVF_phi;
MET_new_etx = MET_RefFinal_STVF_et * cos(MET_RefFinal_STVF_phi);
MET_new_ety = MET_RefFinal_STVF_et * sin(MET_RefFinal_STVF_phi);
*/
  ///////////////////////////////////////////////////

double  InvMass = -99;
if(egamma_trigger && elec_index_met.size()>1){
InvMass = (elec_index_met[0].tlv + elec_index_met[1].tlv).M();
}
else if(muon_trigger && muon_index_met.size()>1){
InvMass = (muon_index_met[0].tlv + muon_index_met[1].tlv).M();
}
else if(elec_index_met.size()==1 && muon_index_met.size()==1){
InvMass = (elec_index_met[0].tlv + muon_index_met[0].tlv).M();
}

Double_t mtNewDefined=-99;
Double_t ptNewDefined=-99;
if(HForRej && Nlepton_lr_1 && Good_Vtx &&  kMETClean && pass_lepton_veto && Only_1lepton){

if(egamma_trigger && elec_index_met.size()>0){
            Double_t t_NewDefinedEle_etx =  MET_new_etx ;
            Double_t t_NewDefinedEle_ety =  MET_new_ety ;
            Double_t t_NewDefinedEle_et = MET_new_et;

             mtNewDefined     =  sqrt(   pow(elec_index_met[0].tlv.Pt() + t_NewDefinedEle_et, 2) -
                                                    ( pow( elec_index_met[0].tlv.Px() + t_NewDefinedEle_etx, 2) +
                                                      pow( elec_index_met[0].tlv.Py() + t_NewDefinedEle_ety, 2)  ));

            ptNewDefined      =  sqrt(   pow( elec_index_met[0].tlv.Px() + t_NewDefinedEle_etx, 2) +
                                                      pow( elec_index_met[0].tlv.Py() + t_NewDefinedEle_ety, 2)  );

}
if(muon_trigger && muon_index_met.size()>0){
      Double_t t_NewDefined_etx = MET_new_etx;
      Double_t t_NewDefined_ety = MET_new_ety;
      Double_t t_NewDefined_et = MET_new_et;

       mtNewDefined     =  sqrt(  pow(muon_index_met[0].tlv.Pt() + t_NewDefined_et, 2)
                                          - pow( muon_index_met[0].tlv.Px() + t_NewDefined_etx, 2)
                                          - pow( muon_index_met[0].tlv.Py() + t_NewDefined_ety, 2) );

            ptNewDefined      =  sqrt(   pow( muon_index_met[0].tlv.Px() + t_NewDefined_etx, 2) + 
                                                      pow( muon_index_met[0].tlv.Py() + t_NewDefined_ety, 2)  );

}

}

bool passMET = true;
if(MET_new_et<25000.)passMET = false;


//Lepton veto
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && egamma_trigger && pass_lepton_veto && passMET){
 h_cutflow_eg_num->Fill(12);
 h_cutflow_eg_wei->Fill(12,Pileup_event_weight);
}
else if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && muon_trigger && pass_lepton_veto && passMET){
 h_cutflow_mu_num->Fill(12);
 h_cutflow_mu_wei->Fill(12,Pileup_event_weight);
}


bool passMT = true;
if(mtNewDefined<40000.)passMT = false;


//Lepton veto
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && egamma_trigger && pass_lepton_veto && passMET && passMT){
 h_cutflow_eg_num->Fill(13);
 h_cutflow_eg_wei->Fill(13,Pileup_event_weight);
}
else if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && muon_trigger && pass_lepton_veto && passMET && passMT){
 h_cutflow_mu_num->Fill(13);
 h_cutflow_mu_wei->Fill(13,Pileup_event_weight);
}


int njet_eta=jet_index_met.size();
int njet_b=0;
int njet_highpt=0;
float jjdr = -99; 
float pass_jjdr = false;
if(jet_index_met.size()>=2 && HForRej && Nlepton_lr_1 && Good_Vtx && kMETClean && pass_lepton_veto && Only_1lepton ){


for(unsigned int j=0; j<jet_index_met.size(); j++){
if(jet_index_met[j].tlv.Pt()>45000)njet_highpt++;
if(jet_index_met[j].jetFitter>0.60173)njet_b++;
//if(jet_index_met[j].jetIP3D_SV1>1.55)njet_b++;
}

int index_i=0;
if(njet_eta==2){
    double jet_eta1 = jet_index_met[0].eta;
    double jet_phi1 = jet_index_met[0].phi;
    double jet_eta2 = jet_index_met[1].eta;
    double jet_phi2 = jet_index_met[1].phi;
    double jj_dphi = caldphi(jet_phi1, jet_phi2);
    double jj_deta = caldeta(jet_eta1, jet_eta2);
    jjdr = caldr(jj_dphi, jj_deta); 
}

if(jjdr > 0.7  || ptNewDefined > 200000) pass_jjdr = true; 

//Fill cutflow
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && egamma_trigger && pass_lepton_veto && passMET && passMT && njet_eta==2){
 h_cutflow_eg_num->Fill(14);
 h_cutflow_eg_wei->Fill(14,Pileup_event_weight);
}
else if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && muon_trigger && pass_lepton_veto && passMET && passMT && njet_eta==2){
 h_cutflow_mu_num->Fill(14);
 h_cutflow_mu_wei->Fill(14,Pileup_event_weight);
}


//Fill cutflow
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && egamma_trigger && pass_lepton_veto && passMET && passMT && njet_eta==2 && njet_b>=1){
 h_cutflow_eg_num->Fill(15);
 h_cutflow_eg_wei->Fill(15,Pileup_event_weight);
}
else if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && muon_trigger && pass_lepton_veto && passMET && passMT && njet_eta==2 && njet_b>=1){
 h_cutflow_mu_num->Fill(15);
 h_cutflow_mu_wei->Fill(15,Pileup_event_weight);
}


//Fill cutflow
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && egamma_trigger && pass_lepton_veto && passMET && passMT && njet_eta==2 && njet_b==2){
 h_cutflow_eg_num->Fill(16);
 h_cutflow_eg_wei->Fill(16,Pileup_event_weight);
}
else if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && muon_trigger && pass_lepton_veto && passMET && passMT && njet_eta==2 && njet_b==2){
 h_cutflow_mu_num->Fill(16);
 h_cutflow_mu_wei->Fill(16,Pileup_event_weight);
}


//Fill cutflow
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && egamma_trigger && pass_lepton_veto && passMET && passMT && njet_eta==2 && njet_b==2 && jet_index_veto.size()<=2){
 h_cutflow_eg_num->Fill(17);
 h_cutflow_eg_wei->Fill(17,Pileup_event_weight);
//if(jjdr<0.7)cout<<" eg : Event number "<< EventNumber << " deta: "<< jet_index_met[0].eta << "  "<<jet_index_met[1].eta <<"  "<<caldeta(jet_index_met[0].eta,jet_index_met[1].eta) << "  dphi:   "<<jet_index_met[0].phi << "   "<< jet_index_met[1].phi<<"    "<<caldphi(jet_index_met[0].phi,jet_index_met[1].phi) <<"  "  << jjdr <<"  "<<endl;
}
else if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && muon_trigger && pass_lepton_veto && passMET && passMT && njet_eta==2 && njet_b==2 && jet_index_veto.size()<=2){
 h_cutflow_mu_num->Fill(17);
 h_cutflow_mu_wei->Fill(17,Pileup_event_weight);
//if(jjdr<0.7)cout<<"mu : Event number "<< EventNumber << " deta: "<< jet_index_met[0].eta << "  "<<jet_index_met[1].eta <<"  "<<caldeta(jet_index_met[0].eta,jet_index_met[1].eta) << "  dphi:   "<<jet_index_met[0].phi << "   "<< jet_index_met[1].phi<<"    "<<caldphi(jet_index_met[0].phi,jet_index_met[1].phi) <<"  "  << jjdr <<"  "<<endl;
}



//Fill cutflow
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && egamma_trigger && pass_lepton_veto && passMET && passMT && njet_eta==2 && njet_b==2 && jet_index_veto.size()<=2 && pass_jjdr){
 h_cutflow_eg_num->Fill(18);
 h_cutflow_eg_wei->Fill(18,Pileup_event_weight);
}
else if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && muon_trigger && pass_lepton_veto && passMET && passMT && njet_eta==2 && njet_b==2 && jet_index_veto.size()<=2 && pass_jjdr){
 h_cutflow_mu_num->Fill(18);
 h_cutflow_mu_wei->Fill(18,Pileup_event_weight);
}


//Fill cutflow
if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && egamma_trigger && pass_lepton_veto && passMET      && passMT && njet_eta==2 && njet_b==2 && jet_index_veto.size()<=2 && pass_jjdr && njet_highpt>0){
 h_cutflow_eg_num->Fill(19);
 h_cutflow_eg_wei->Fill(19,Pileup_event_weight);

if(ptNewDefined < 50000){
 h_cutflow_eg_num->Fill(20);
 h_cutflow_eg_wei->Fill(20,Pileup_event_weight);
} 
else if (ptNewDefined < 100000){
 h_cutflow_eg_num->Fill(21);
 h_cutflow_eg_wei->Fill(21,Pileup_event_weight);
}
else if (ptNewDefined < 200000){
 h_cutflow_eg_num->Fill(22);
 h_cutflow_eg_wei->Fill(22,Pileup_event_weight);
}
else{
 h_cutflow_eg_num->Fill(23);
 h_cutflow_eg_wei->Fill(23,Pileup_event_weight);
}

}
else if(HForRej && h_pass_grl && Good_Vtx && Pass_jetclean && pass_lar_error && kMETClean && Nlepton_lr_1 && Only_1lepton && muon_trigger && pass_lepton_veto && passMET && passMT && njet_eta==2 && njet_b==2 && jet_index_veto.size()<=2 && pass_jjdr && njet_highpt>0){
 h_cutflow_mu_num->Fill(19);
 h_cutflow_mu_wei->Fill(19,Pileup_event_weight);
if(ptNewDefined < 50000){
 h_cutflow_mu_num->Fill(20);
 h_cutflow_mu_wei->Fill(20,Pileup_event_weight);
}
else if (ptNewDefined < 100000){
 h_cutflow_mu_num->Fill(21);
 h_cutflow_mu_wei->Fill(21,Pileup_event_weight);
}
else if (ptNewDefined < 200000){
 h_cutflow_mu_num->Fill(22);
 h_cutflow_mu_wei->Fill(22,Pileup_event_weight);
}
else{
 h_cutflow_mu_num->Fill(23);
 h_cutflow_mu_wei->Fill(23,Pileup_event_weight);
}

}


}

//Data will reject the events that does not have one lepton, but MC have to keep all the events for normalization
bool select_to_save = false;
if(kIsSave){
double signal_e = 0;
double signal_m = 0;
for(unsigned int i = 0; i < elec_index_save.size(); i++) {
if( (elec_index_save[i].pass_tightcut) && (elec_index_save[i].pt > 25000)  ) signal_e ++;
}

for(unsigned int i = 0; i < muon_index_save.size(); i++) {
if( (muon_index_save[i].pass_tightcut) && (muon_index_save[i].pt > 25000)  ) signal_m ++;
}

if(signal_e + signal_m > 0 )select_to_save = true;

//cout<<"test electron "<< EventNumber << signal_e - elec_index_met.size()<<endl;
//cout<<"test muon "<< EventNumber << signal_m - muon_index_met.size()<<endl;
}

if(kIsSave && ( (kIsData && select_to_save ) || (!kIsData))  ){//start to fill branches
h_jet_n = jet_index_save.size();
for(int i = 0; i<h_jet_n; i++){
h_jet_E ->push_back( jet_index_save[i].E);
h_jet_pt ->push_back( jet_index_save[i].pt);
h_jet_pt_ori ->push_back( jet_index_save[i].pt_ori);
h_jet_eta ->push_back( jet_index_save[i].eta);
h_jet_phi ->push_back( jet_index_save[i].phi);
h_jet_weight ->push_back( jet_index_save[i].jetFitter);
h_jet_jvf ->push_back( jet_index_save[i].jet_jvf);
h_jet_bad ->push_back(jet_index_save[i].jetbad); 
h_jet_Btagsf ->push_back(jet_index_save[i].jet_Bsf); 
h_jet_Btagsferr ->push_back(jet_index_save[i].jet_Bsferr); 
h_jet_Btagsf_0 ->push_back(jet_index_save[i].jet_Bsf_0);
h_jet_Btagsferr_0 ->push_back(jet_index_save[i].jet_Bsferr_0);
h_jet_Btagsf_1 ->push_back(jet_index_save[i].jet_Bsf_1);
h_jet_Btagsferr_1 ->push_back(jet_index_save[i].jet_Bsferr_1);
h_jet_Btagsf_2 ->push_back(jet_index_save[i].jet_Bsf_2);
h_jet_Btagsferr_2 ->push_back(jet_index_save[i].jet_Bsferr_2);
h_jet_Btagsf_3 ->push_back(jet_index_save[i].jet_Bsf_3);
h_jet_Btagsferr_3 ->push_back(jet_index_save[i].jet_Bsferr_3);
h_jet_Btagsf_4 ->push_back(jet_index_save[i].jet_Bsf_4);
h_jet_Btagsferr_4 ->push_back(jet_index_save[i].jet_Bsferr_4);

h_jet_ResFactor->push_back(jet_index_save[i].JER_smear);
h_jet_ResFactorSys->push_back(jet_index_save[i].JER_smear_sys);
h_jet_ScaleUncertUp->push_back(jet_index_save[i].JES_uncert_up);
h_jet_ScaleUncertDo->push_back(jet_index_save[i].JES_uncert_down);
h_jet_ScaleUncertNPV->push_back(jet_index_save[i].JES_uncert_npv);
h_jet_ScaleUncertMU->push_back(jet_index_save[i].JES_uncert_mu);
h_jet_Pass_LowPt->push_back(jet_index_save[i].pass_looseptcut);
h_jet_Pass_HighPt->push_back(jet_index_save[i].pass_tightptcut);
h_jet_Pass_TightCut->push_back(jet_index_save[i].pass_tightcut);
h_jet_label->push_back(jet_index_save[i].truth_label);

}

h_elec_n = elec_index_save.size();
for(int i = 0; i< h_elec_n; i++){
h_elec_E  ->push_back(elec_index_save[i].E);
h_elec_pt ->push_back(elec_index_save[i].pt);
h_elec_pt_ori ->push_back(elec_index_save[i].pt_ori);
h_elec_pt_up ->push_back(elec_index_save[i].Et_up);
h_elec_pt_down ->push_back(elec_index_save[i].Et_down);
h_elec_pt_Rup ->push_back(elec_index_save[i].Et_Rup);
h_elec_pt_Rdown ->push_back(elec_index_save[i].Et_Rdown);
h_elec_eta ->push_back(elec_index_save[i].eta);
h_elec_phi ->push_back(elec_index_save[i].phi);
h_elec_sumpt ->push_back(elec_index_save[i].SumPt);
h_elec_sumet ->push_back(elec_index_save[i].SumEt);
h_elec_charge ->push_back(elec_index_save[i].charge);
h_elec_mt ->push_back(mtNewDefined);

h_elec_sf ->push_back(elec_index_save[i].sf);
h_elec_sf_err->push_back(elec_index_save[i].sf_err);
h_elec_recsf->push_back(elec_index_save[i].rec_sf);
h_elec_recsf_err->push_back(elec_index_save[i].rec_sf_err);  
h_elec_trig_e20->push_back(elec_index_save[i].trigsf_e20);   
h_elec_trig_e22->push_back(elec_index_save[i].trigsf_e22);   
h_elec_trig_e22vh->push_back(elec_index_save[i].trigsf_e22vh); 

h_elec_Pass_LowPt->push_back(elec_index_save[i].pass_looseptcut);
h_elec_Pass_HighPt->push_back(elec_index_save[i].pass_tightptcut);
h_elec_Pass_TightCut->push_back(elec_index_save[i].pass_tightcut);
h_elec_tight->push_back(elec_index_save[i].isTight);
h_elec_medium->push_back(elec_index_save[i].isMedium);
}

h_muon_n = muon_index_save.size();
for(int i = 0; i<h_muon_n; i++){
h_muon_E  ->push_back( muon_index_save[i].E);
h_muon_pt ->push_back( muon_index_save[i].pt);
h_muon_pt_ms ->push_back( muon_index_save[i].pt_MS);
h_muon_pt_id ->push_back( muon_index_save[i].pt_ID);
h_muon_pt_ori ->push_back( muon_index_save[i].pt_ori);
h_muon_pt_ms_up ->push_back( muon_index_save[i].Et_ms_up);
h_muon_pt_ms_down ->push_back( muon_index_save[i].Et_ms_down);
h_muon_pt_id_up ->push_back( muon_index_save[i].Et_id_up);
h_muon_pt_id_down ->push_back( muon_index_save[i].Et_id_down);
h_muon_pt_MS_ms_up ->push_back( muon_index_save[i].EtMS_ms_up);
h_muon_pt_MS_ms_down ->push_back( muon_index_save[i].EtMS_ms_down);
h_muon_pt_MS_id_up ->push_back( muon_index_save[i].EtMS_id_up);
h_muon_pt_MS_id_down ->push_back( muon_index_save[i].EtMS_id_down);
h_muon_pt_ID_ms_up ->push_back( muon_index_save[i].EtID_ms_up);
h_muon_pt_ID_ms_down ->push_back( muon_index_save[i].EtID_ms_down);
h_muon_pt_ID_id_up ->push_back( muon_index_save[i].EtID_id_up);
h_muon_pt_ID_id_down ->push_back( muon_index_save[i].EtID_id_down);

h_muon_eta ->push_back( muon_index_save[i].eta);
h_muon_phi ->push_back( muon_index_save[i].phi);
h_muon_sumpt ->push_back( muon_index_save[i].SumPt);
h_muon_sumet ->push_back( muon_index_save[i].SumEt);
h_muon_charge ->push_back( muon_index_save[i].charge);
h_muon_theta ->push_back( muon_index_save[i].theta);
double m_px = muon_index_save[i].tlv.Px();
double m_py = muon_index_save[i].tlv.Py();
h_muon_mt ->push_back(mtNewDefined);
h_muon_sf ->push_back(muon_index_save[i].muon_sf);
h_muon_sf_Sta_err->push_back(muon_index_save[i].muon_sf_Sta_err);
h_muon_sf_Sys_err->push_back(muon_index_save[i].muon_sf_Sys_err);
h_muon_energyloss->push_back(muon_index_save[i].energy_loss);
h_muon_not_overlap->push_back(muon_index_save[i].not_overlap);
h_muon_Pass_LowPt->push_back(muon_index_save[i].pass_looseptcut);
h_muon_Pass_HighPt->push_back(muon_index_save[i].pass_tightptcut);
h_muon_Pass_TightCut->push_back(muon_index_save[i].pass_tightcut);
h_muon_isCombine->push_back(muon_index_save[i].isCombine);
h_muon_isStandAlone->push_back(muon_index_save[i].isStandAlone);
h_muon_isCalo->push_back(muon_index_save[i].isCalo);
h_muon_tight->push_back(muon_index_save[i].isTight);
h_muon_medium->push_back(muon_index_save[i].isMedium);
}
h_muon_trigsf = trig_SF.first;
h_muon_trigsfsys = trig_SF.second;

if(!kIsData){
h_RunNumber=mc_channel_number;
}
else h_RunNumber = RunNumber;
h_EventNumber=EventNumber;
h_lbn=lbn;
h_mu=averageIntPerXing;

if(muon_trigger ) {
h_EF_mu18_MG=1;
}else h_EF_mu18_MG=0;

if(egamma_trigger){
h_EF_e20_medium=1;
}else h_EF_e20_medium=0;

if(b_EF_xe80T_tclcw_loose) h_EF_xe80T_tclcw_loose=(EF_xe80T_tclcw_loose)?1:0;
else h_EF_xe80T_tclcw_loose =0;
if(b_EF_xe80_tclcw_loose) h_EF_xe80_tclcw_loose=(EF_xe80_tclcw_loose)?1:0;
else h_EF_xe80_tclcw_loose=0;

h_met = MET_new_et;
h_met_box = MET_RefFinal_et;
h_met_CellOutUp=CellOutUp;
h_met_CellOutDo=CellOutDo;
h_met_SoftJetUp=SoftJetUp;
h_met_SoftJetDo=SoftJetDo;
h_met_SoftJetResoUp=SoftJetResoUp;
h_met_SoftJetResoDo=SoftJetResoDo;
h_stvf_SoftJetUp=SoftJetUp_stvf;
h_stvf_SoftJetDo=SoftJetDo_stvf;
h_stvf_SoftJetResoUp=SoftJetResoUp_stvf;
h_stvf_SoftJetResoDo=SoftJetResoDo_stvf;


 h_refinal_met = MET_RefFinal_et;
 h_refinal_metphi = MET_RefFinal_phi;
 h_refinal_sumet = MET_RefFinal_sumet;
 h_refinal_metphi_C = MET_RefFinal_phi_CentralReg;
 h_refinal_sumet_C = MET_RefFinal_sumet_CentralReg;
 h_refinal_etx_C = MET_RefFinal_etx_CentralReg;
 h_refinal_ety_C = MET_RefFinal_ety_CentralReg;
 h_refinal_metphi_E = MET_RefFinal_phi_EndcapRegion;
 h_refinal_sumet_E = MET_RefFinal_sumet_EndcapRegion;
 h_refinal_etx_E = MET_RefFinal_etx_EndcapRegion;
 h_refinal_ety_E = MET_RefFinal_ety_EndcapRegion;
 h_refinal_metphi_F = MET_RefFinal_phi_ForwardReg;
 h_refinal_sumet_F = MET_RefFinal_sumet_ForwardReg;
 h_refinal_etx_F = MET_RefFinal_etx_ForwardReg;
 h_refinal_ety_F = MET_RefFinal_ety_ForwardReg;

 h_track_met = MET_Track_et;
 h_track_metphi = MET_Track_phi;
 h_track_sumet = MET_Track_sumet;
 h_track_metphi_C = MET_Track_phi_CentralReg;
 h_track_sumet_C = MET_Track_sumet_CentralReg;
 h_track_etx_C = MET_Track_etx_CentralReg;
 h_track_ety_C = MET_Track_ety_CentralReg;
 h_track_metphi_E = MET_Track_phi_EndcapRegion;
 h_track_sumet_E = MET_Track_sumet_EndcapRegion;
 h_track_etx_E = MET_Track_etx_EndcapRegion;
 h_track_ety_E = MET_Track_ety_EndcapRegion;
 h_track_metphi_F = MET_Track_phi_ForwardReg;
 h_track_sumet_F = MET_Track_sumet_ForwardReg;
 h_track_etx_F = MET_Track_etx_ForwardReg;
 h_track_ety_F = MET_Track_ety_ForwardReg;

 h_refinal_stvf_met = MET_RefFinal_STVF_et;
 h_refinal_stvf_metphi = MET_RefFinal_STVF_phi;
 h_refinal_stvf_sumet = MET_RefFinal_STVF_sumet;
 h_refinal_stvf_metphi_C = MET_RefFinal_STVF_phi_CentralReg;
 h_refinal_stvf_sumet_C = MET_RefFinal_STVF_sumet_CentralReg;
 h_refinal_stvf_etx_C = MET_RefFinal_STVF_etx_CentralReg;
 h_refinal_stvf_ety_C = MET_RefFinal_STVF_ety_CentralReg;
 h_refinal_stvf_metphi_E = MET_RefFinal_STVF_phi_EndcapRegion;
 h_refinal_stvf_sumet_E = MET_RefFinal_STVF_sumet_EndcapRegion;
 h_refinal_stvf_etx_E = MET_RefFinal_STVF_etx_EndcapRegion;
 h_refinal_stvf_ety_E = MET_RefFinal_STVF_ety_EndcapRegion;
 h_refinal_stvf_metphi_F = MET_RefFinal_STVF_phi_ForwardReg;
 h_refinal_stvf_sumet_F = MET_RefFinal_STVF_sumet_ForwardReg;
 h_refinal_stvf_etx_F = MET_RefFinal_STVF_etx_ForwardReg;
 h_refinal_stvf_ety_F = MET_RefFinal_STVF_ety_ForwardReg;

 h_cellout_eflow_met = MET_CellOut_Eflow_et;
 h_cellout_eflow_metphi = MET_CellOut_Eflow_phi;
 h_cellout_eflow_sumet = MET_CellOut_Eflow_sumet;
 h_cellout_eflow_metphi_C = MET_CellOut_Eflow_phi_CentralReg;
 h_cellout_eflow_sumet_C = MET_CellOut_Eflow_sumet_CentralReg;
 h_cellout_eflow_etx_C = MET_CellOut_Eflow_etx_CentralReg;
 h_cellout_eflow_ety_C = MET_CellOut_Eflow_ety_CentralReg;
 h_cellout_eflow_metphi_E = MET_CellOut_Eflow_phi_EndcapRegion;
 h_cellout_eflow_sumet_E = MET_CellOut_Eflow_sumet_EndcapRegion;
 h_cellout_eflow_etx_E = MET_CellOut_Eflow_etx_EndcapRegion;
 h_cellout_eflow_ety_E = MET_CellOut_Eflow_ety_EndcapRegion;
 h_cellout_eflow_metphi_F = MET_CellOut_Eflow_phi_ForwardReg;
 h_cellout_eflow_sumet_F = MET_CellOut_Eflow_sumet_ForwardReg;
 h_cellout_eflow_etx_F = MET_CellOut_Eflow_etx_ForwardReg;
 h_cellout_eflow_ety_F = MET_CellOut_Eflow_ety_ForwardReg;


 h_refjet_met = MET_RefJet_et;
 h_refjet_metphi = MET_RefJet_phi;
 h_refjet_sumet = MET_RefJet_sumet;
 h_refjet_metphi_C = MET_RefJet_phi_CentralReg;
 h_refjet_sumet_C = MET_RefJet_sumet_CentralReg;
 h_refjet_etx_C = MET_RefJet_etx_CentralReg;
 h_refjet_ety_C = MET_RefJet_ety_CentralReg;
 h_refjet_metphi_E = MET_RefJet_phi_EndcapRegion;
 h_refjet_sumet_E = MET_RefJet_sumet_EndcapRegion;
 h_refjet_etx_E = MET_RefJet_etx_EndcapRegion;
 h_refjet_ety_E = MET_RefJet_ety_EndcapRegion;
 h_refjet_metphi_F = MET_RefJet_phi_ForwardReg;
 h_refjet_sumet_F = MET_RefJet_sumet_ForwardReg;
 h_refjet_etx_F = MET_RefJet_etx_ForwardReg;
 h_refjet_ety_F = MET_RefJet_ety_ForwardReg;


 h_softjets_met = MET_SoftJets_et;
 h_softjets_metphi = MET_SoftJets_phi;
 h_softjets_sumet = MET_SoftJets_sumet;
 h_softjets_metphi_C = MET_SoftJets_phi_CentralReg;
 h_softjets_sumet_C = MET_SoftJets_sumet_CentralReg;
 h_softjets_etx_C = MET_SoftJets_etx_CentralReg;
 h_softjets_ety_C = MET_SoftJets_ety_CentralReg;
 h_softjets_metphi_E = MET_SoftJets_phi_EndcapRegion;
 h_softjets_sumet_E = MET_SoftJets_sumet_EndcapRegion;
 h_softjets_etx_E = MET_SoftJets_etx_EndcapRegion;
 h_softjets_ety_E = MET_SoftJets_ety_EndcapRegion;
 h_softjets_metphi_F = MET_SoftJets_phi_ForwardReg;
 h_softjets_sumet_F = MET_SoftJets_sumet_ForwardReg;
 h_softjets_etx_F = MET_SoftJets_etx_ForwardReg;
 h_softjets_ety_F = MET_SoftJets_ety_ForwardReg;


 h_truth_etx = MET_Truth_NonInt_etx;
 h_truth_ety = MET_Truth_NonInt_ety;
 h_truth_phi = MET_Truth_NonInt_phi;
 h_truth_et = MET_Truth_NonInt_et;
 h_truth_sumet = MET_Truth_NonInt_sumet;


h_metx = MET_new_etx;
h_mety = MET_new_ety;
h_metphi = MET_new_phi;
h_mt = mtNewDefined;
h_pt = ptNewDefined;
h_mll = InvMass;

if(HForRej){
h_HforRej=1;
}else h_HforRej=0;

h_weight = Pileup_event_weight;
h_weight_1 = Pileup_event_weight_1;
h_weight_2 = Pileup_event_weight_2;
h_weight_3 = Pileup_event_weight_3;
h_weight_4 = Pileup_event_weight_4;
h_Pweight = event_weight;
if(Pass_jetclean)h_jetclean = 1;
else h_jetclean=0;
if(kMETClean)h_metclean = 1;
else h_metclean = 0;

h_NGoodVtx = N_Good_Vtx; 

if(pass_lepton_veto)h_pass_lepton_veto = 1;
else h_pass_lepton_veto = 0;

if(pass_jet_veto)h_pass_jet_veto =1;
else h_pass_jet_veto=0;

h_njet = jet_index_met.size();
h_nbjet = njet_b;
h_nhjet = njet_highpt;
h_jjdr = jjdr;

fFile->cd();
m_tree->Fill();

}//finish fill branches


if(kIsSimple && ( (kIsData && ((elec_index_met.size() + muon_index_met.size() )>0 )) || (!kIsData))  ){//start to fill branches
h_jet_n = jet_index_met.size();
for(int i = 0; i<h_jet_n; i++){
h_jet_E ->push_back( jet_index_met[i].E);
h_jet_pt ->push_back( jet_index_met[i].pt);
h_jet_pt_ori ->push_back( jet_index_met[i].pt_ori);
h_jet_eta ->push_back( jet_index_met[i].eta);
h_jet_phi ->push_back( jet_index_met[i].phi);
h_jet_weight ->push_back( jet_index_met[i].jetFitter);
h_jet_jvf ->push_back( jet_index_met[i].jet_jvf);
h_jet_bad ->push_back(jet_index_met[i].jetbad); 
h_jet_Btagsf ->push_back(jet_index_met[i].jet_Bsf); 
h_jet_Btagsferr ->push_back(jet_index_met[i].jet_Bsferr); 
h_jet_Btagsf_0 ->push_back(jet_index_met[i].jet_Bsf_0);
h_jet_Btagsferr_0 ->push_back(jet_index_met[i].jet_Bsferr_0);
h_jet_Btagsf_1 ->push_back(jet_index_met[i].jet_Bsf_1);
h_jet_Btagsferr_1 ->push_back(jet_index_met[i].jet_Bsferr_1);
h_jet_Btagsf_2 ->push_back(jet_index_met[i].jet_Bsf_2);
h_jet_Btagsferr_2 ->push_back(jet_index_met[i].jet_Bsferr_2);
h_jet_Btagsf_3 ->push_back(jet_index_met[i].jet_Bsf_3);
h_jet_Btagsferr_3 ->push_back(jet_index_met[i].jet_Bsferr_3);
h_jet_Btagsf_4 ->push_back(jet_index_met[i].jet_Bsf_4);
h_jet_Btagsferr_4 ->push_back(jet_index_met[i].jet_Bsferr_4);

h_jet_ResFactor->push_back(jet_index_met[i].JER_smear);
h_jet_ResFactorSys->push_back(jet_index_met[i].JER_smear_sys);
h_jet_ScaleUncertUp->push_back(jet_index_met[i].JES_uncert_up);
h_jet_ScaleUncertDo->push_back(jet_index_met[i].JES_uncert_down);
h_jet_ScaleUncertNPV->push_back(jet_index_met[i].JES_uncert_npv);
h_jet_ScaleUncertMU->push_back(jet_index_met[i].JES_uncert_mu);
h_jet_Pass_LowPt->push_back(jet_index_met[i].pass_looseptcut);
h_jet_Pass_HighPt->push_back(jet_index_met[i].pass_tightptcut);
h_jet_Pass_TightCut->push_back(jet_index_met[i].pass_tightcut);
h_jet_label->push_back(jet_index_met[i].truth_label);

}

h_elec_n = elec_index_met.size();
for(int i = 0; i< h_elec_n; i++){
h_elec_E  ->push_back(elec_index_met[i].E);
h_elec_pt ->push_back(elec_index_met[i].pt);
h_elec_pt_ori ->push_back(elec_index_met[i].pt_ori);
h_elec_pt_up ->push_back(elec_index_met[i].Et_up);
h_elec_pt_down ->push_back(elec_index_met[i].Et_down);
h_elec_pt_Rup ->push_back(elec_index_met[i].Et_Rup);
h_elec_pt_Rdown ->push_back(elec_index_met[i].Et_Rdown);
h_elec_eta ->push_back(elec_index_met[i].eta);
h_elec_phi ->push_back(elec_index_met[i].phi);
h_elec_sumpt ->push_back(elec_index_met[i].SumPt);
h_elec_sumet ->push_back(elec_index_met[i].SumEt);
h_elec_charge ->push_back(elec_index_met[i].charge);
h_elec_mt ->push_back(mtNewDefined);

h_elec_sf ->push_back(elec_index_met[i].sf);
h_elec_sf_err->push_back(elec_index_met[i].sf_err);
h_elec_recsf->push_back(elec_index_met[i].rec_sf);
h_elec_recsf_err->push_back(elec_index_met[i].rec_sf_err);  
h_elec_trig_e20->push_back(elec_index_met[i].trigsf_e20);   
h_elec_trig_e22->push_back(elec_index_met[i].trigsf_e22);   
h_elec_trig_e22vh->push_back(elec_index_met[i].trigsf_e22vh); 

h_elec_Pass_LowPt->push_back(elec_index_met[i].pass_looseptcut);
h_elec_Pass_HighPt->push_back(elec_index_met[i].pass_tightptcut);
h_elec_Pass_TightCut->push_back(elec_index_met[i].pass_tightcut);
h_elec_tight->push_back(elec_index_met[i].isTight);
h_elec_medium->push_back(elec_index_met[i].isMedium);
}

h_muon_n = muon_index_met.size();
for(int i = 0; i<h_muon_n; i++){
h_muon_E  ->push_back( muon_index_met[i].E);
h_muon_pt ->push_back( muon_index_met[i].pt);
h_muon_pt_ms ->push_back( muon_index_met[i].pt_MS);
h_muon_pt_id ->push_back( muon_index_met[i].pt_ID);
h_muon_pt_ori ->push_back( muon_index_met[i].pt_ori);
h_muon_pt_ms_up ->push_back( muon_index_met[i].Et_ms_up);
h_muon_pt_ms_down ->push_back( muon_index_met[i].Et_ms_down);
h_muon_pt_id_up ->push_back( muon_index_met[i].Et_id_up);
h_muon_pt_id_down ->push_back( muon_index_met[i].Et_id_down);
h_muon_pt_MS_ms_up ->push_back( muon_index_met[i].EtMS_ms_up);
h_muon_pt_MS_ms_down ->push_back( muon_index_met[i].EtMS_ms_down);
h_muon_pt_MS_id_up ->push_back( muon_index_met[i].EtMS_id_up);
h_muon_pt_MS_id_down ->push_back( muon_index_met[i].EtMS_id_down);
h_muon_pt_ID_ms_up ->push_back( muon_index_met[i].EtID_ms_up);
h_muon_pt_ID_ms_down ->push_back( muon_index_met[i].EtID_ms_down);
h_muon_pt_ID_id_up ->push_back( muon_index_met[i].EtID_id_up);
h_muon_pt_ID_id_down ->push_back( muon_index_met[i].EtID_id_down);

h_muon_eta ->push_back( muon_index_met[i].eta);
h_muon_phi ->push_back( muon_index_met[i].phi);
h_muon_sumpt ->push_back( muon_index_met[i].SumPt);
h_muon_sumet ->push_back( muon_index_met[i].SumEt);
h_muon_charge ->push_back( muon_index_met[i].charge);
h_muon_theta ->push_back( muon_index_met[i].theta);
double m_px = muon_index_met[i].tlv.Px();
double m_py = muon_index_met[i].tlv.Py();
h_muon_mt ->push_back(mtNewDefined);
h_muon_sf ->push_back(muon_index_met[i].muon_sf);
h_muon_sf_Sta_err->push_back(muon_index_met[i].muon_sf_Sta_err);
h_muon_sf_Sys_err->push_back(muon_index_met[i].muon_sf_Sys_err);
h_muon_energyloss->push_back(muon_index_met[i].energy_loss);
h_muon_not_overlap->push_back(muon_index_met[i].not_overlap);
h_muon_Pass_LowPt->push_back(muon_index_met[i].pass_looseptcut);
h_muon_Pass_HighPt->push_back(muon_index_met[i].pass_tightptcut);
h_muon_Pass_TightCut->push_back(muon_index_met[i].pass_tightcut);
h_muon_isCombine->push_back(muon_index_met[i].isCombine);
h_muon_isStandAlone->push_back(muon_index_met[i].isStandAlone);
h_muon_isCalo->push_back(muon_index_met[i].isCalo);
h_muon_tight->push_back(muon_index_met[i].isTight);
h_muon_medium->push_back(muon_index_met[i].isMedium);
}
h_muon_trigsf = trig_SF.first;
h_muon_trigsfsys = trig_SF.second;

if(!kIsData){
h_RunNumber=mc_channel_number;
}
else h_RunNumber = RunNumber;
h_EventNumber=EventNumber;
h_lbn=lbn;
h_mu=averageIntPerXing;

if(muon_trigger ) {
h_EF_mu18_MG=1;
}else h_EF_mu18_MG=0;

if(egamma_trigger){
h_EF_e20_medium=1;
}else h_EF_e20_medium=0;

h_EF_xe80T_tclcw_loose=(EF_xe80T_tclcw_loose)?1:0;
h_EF_xe80_tclcw_loose=(EF_xe80_tclcw_loose)?1:0;

h_met = MET_new_et;
h_met_box = MET_RefFinal_et;
h_met_CellOutUp=CellOutUp;
h_met_CellOutDo=CellOutDo;
h_met_SoftJetUp=SoftJetUp;
h_met_SoftJetDo=SoftJetDo;
h_met_SoftJetResoUp=SoftJetResoUp;
h_met_SoftJetResoDo=SoftJetResoDo;
h_stvf_SoftJetUp=SoftJetUp_stvf;
h_stvf_SoftJetDo=SoftJetDo_stvf;
h_stvf_SoftJetResoUp=SoftJetResoUp_stvf;
h_stvf_SoftJetResoDo=SoftJetResoDo_stvf;



 h_refinal_met = MET_RefFinal_et;
 h_refinal_metphi = MET_RefFinal_phi;
 h_refinal_sumet = MET_RefFinal_sumet;
 h_refinal_metphi_C = MET_RefFinal_phi_CentralReg;
 h_refinal_sumet_C = MET_RefFinal_sumet_CentralReg;
 h_refinal_etx_C = MET_RefFinal_etx_CentralReg;
 h_refinal_ety_C = MET_RefFinal_ety_CentralReg;
 h_refinal_metphi_E = MET_RefFinal_phi_EndcapRegion;
 h_refinal_sumet_E = MET_RefFinal_sumet_EndcapRegion;
 h_refinal_etx_E = MET_RefFinal_etx_EndcapRegion;
 h_refinal_ety_E = MET_RefFinal_ety_EndcapRegion;
 h_refinal_metphi_F = MET_RefFinal_phi_ForwardReg;
 h_refinal_sumet_F = MET_RefFinal_sumet_ForwardReg;
 h_refinal_etx_F = MET_RefFinal_etx_ForwardReg;
 h_refinal_ety_F = MET_RefFinal_ety_ForwardReg;

 h_track_met = MET_Track_et;
 h_track_metphi = MET_Track_phi;
 h_track_sumet = MET_Track_sumet;
 h_track_metphi_C = MET_Track_phi_CentralReg;
 h_track_sumet_C = MET_Track_sumet_CentralReg;
 h_track_etx_C = MET_Track_etx_CentralReg;
 h_track_ety_C = MET_Track_ety_CentralReg;
 h_track_metphi_E = MET_Track_phi_EndcapRegion;
 h_track_sumet_E = MET_Track_sumet_EndcapRegion;
 h_track_etx_E = MET_Track_etx_EndcapRegion;
 h_track_ety_E = MET_Track_ety_EndcapRegion;
 h_track_metphi_F = MET_Track_phi_ForwardReg;
 h_track_sumet_F = MET_Track_sumet_ForwardReg;
 h_track_etx_F = MET_Track_etx_ForwardReg;
 h_track_ety_F = MET_Track_ety_ForwardReg;

 h_refinal_stvf_met = MET_RefFinal_STVF_et;
 h_refinal_stvf_metphi = MET_RefFinal_STVF_phi;
 h_refinal_stvf_sumet = MET_RefFinal_STVF_sumet;
 h_refinal_stvf_metphi_C = MET_RefFinal_STVF_phi_CentralReg;
 h_refinal_stvf_sumet_C = MET_RefFinal_STVF_sumet_CentralReg;
 h_refinal_stvf_etx_C = MET_RefFinal_STVF_etx_CentralReg;
 h_refinal_stvf_ety_C = MET_RefFinal_STVF_ety_CentralReg;
 h_refinal_stvf_metphi_E = MET_RefFinal_STVF_phi_EndcapRegion;
 h_refinal_stvf_sumet_E = MET_RefFinal_STVF_sumet_EndcapRegion;
 h_refinal_stvf_etx_E = MET_RefFinal_STVF_etx_EndcapRegion;
 h_refinal_stvf_ety_E = MET_RefFinal_STVF_ety_EndcapRegion;
 h_refinal_stvf_metphi_F = MET_RefFinal_STVF_phi_ForwardReg;
 h_refinal_stvf_sumet_F = MET_RefFinal_STVF_sumet_ForwardReg;
 h_refinal_stvf_etx_F = MET_RefFinal_STVF_etx_ForwardReg;
 h_refinal_stvf_ety_F = MET_RefFinal_STVF_ety_ForwardReg;

 h_cellout_eflow_met = MET_CellOut_Eflow_et;
 h_cellout_eflow_metphi = MET_CellOut_Eflow_phi;
 h_cellout_eflow_sumet = MET_CellOut_Eflow_sumet;
 h_cellout_eflow_metphi_C = MET_CellOut_Eflow_phi_CentralReg;
 h_cellout_eflow_sumet_C = MET_CellOut_Eflow_sumet_CentralReg;
 h_cellout_eflow_etx_C = MET_CellOut_Eflow_etx_CentralReg;
 h_cellout_eflow_ety_C = MET_CellOut_Eflow_ety_CentralReg;
 h_cellout_eflow_metphi_E = MET_CellOut_Eflow_phi_EndcapRegion;
 h_cellout_eflow_sumet_E = MET_CellOut_Eflow_sumet_EndcapRegion;
 h_cellout_eflow_etx_E = MET_CellOut_Eflow_etx_EndcapRegion;
 h_cellout_eflow_ety_E = MET_CellOut_Eflow_ety_EndcapRegion;
 h_cellout_eflow_metphi_F = MET_CellOut_Eflow_phi_ForwardReg;
 h_cellout_eflow_sumet_F = MET_CellOut_Eflow_sumet_ForwardReg;
 h_cellout_eflow_etx_F = MET_CellOut_Eflow_etx_ForwardReg;
 h_cellout_eflow_ety_F = MET_CellOut_Eflow_ety_ForwardReg;


 h_refjet_met = MET_RefJet_et;
 h_refjet_metphi = MET_RefJet_phi;
 h_refjet_sumet = MET_RefJet_sumet;
 h_refjet_metphi_C = MET_RefJet_phi_CentralReg;
 h_refjet_sumet_C = MET_RefJet_sumet_CentralReg;
 h_refjet_etx_C = MET_RefJet_etx_CentralReg;
 h_refjet_ety_C = MET_RefJet_ety_CentralReg;
 h_refjet_metphi_E = MET_RefJet_phi_EndcapRegion;
 h_refjet_sumet_E = MET_RefJet_sumet_EndcapRegion;
 h_refjet_etx_E = MET_RefJet_etx_EndcapRegion;
 h_refjet_ety_E = MET_RefJet_ety_EndcapRegion;
 h_refjet_metphi_F = MET_RefJet_phi_ForwardReg;
 h_refjet_sumet_F = MET_RefJet_sumet_ForwardReg;
 h_refjet_etx_F = MET_RefJet_etx_ForwardReg;
 h_refjet_ety_F = MET_RefJet_ety_ForwardReg;


 h_softjets_met = MET_SoftJets_et;
 h_softjets_metphi = MET_SoftJets_phi;
 h_softjets_sumet = MET_SoftJets_sumet;
 h_softjets_metphi_C = MET_SoftJets_phi_CentralReg;
 h_softjets_sumet_C = MET_SoftJets_sumet_CentralReg;
 h_softjets_etx_C = MET_SoftJets_etx_CentralReg;
 h_softjets_ety_C = MET_SoftJets_ety_CentralReg;
 h_softjets_metphi_E = MET_SoftJets_phi_EndcapRegion;
 h_softjets_sumet_E = MET_SoftJets_sumet_EndcapRegion;
 h_softjets_etx_E = MET_SoftJets_etx_EndcapRegion;
 h_softjets_ety_E = MET_SoftJets_ety_EndcapRegion;
 h_softjets_metphi_F = MET_SoftJets_phi_ForwardReg;
 h_softjets_sumet_F = MET_SoftJets_sumet_ForwardReg;
 h_softjets_etx_F = MET_SoftJets_etx_ForwardReg;
 h_softjets_ety_F = MET_SoftJets_ety_ForwardReg;


 h_truth_etx = MET_Truth_NonInt_etx;
 h_truth_ety = MET_Truth_NonInt_ety;
 h_truth_phi = MET_Truth_NonInt_phi;
 h_truth_et = MET_Truth_NonInt_et;
 h_truth_sumet = MET_Truth_NonInt_sumet;


h_metx = MET_new_etx;
h_mety = MET_new_ety;
h_metphi = MET_new_phi;
h_mt = mtNewDefined;
h_pt = ptNewDefined;
h_mll = InvMass;

if(HForRej){
h_HforRej=1;
}else h_HforRej=0;

h_weight = Pileup_event_weight;
h_weight_1 = Pileup_event_weight_1;
h_weight_2 = Pileup_event_weight_2;
h_weight_3 = Pileup_event_weight_3;
h_weight_4 = Pileup_event_weight_4;
h_Pweight = event_weight;
if(Pass_jetclean)h_jetclean = 1;
else h_jetclean=0;
if(kMETClean)h_metclean = 1;
else h_metclean = 0;

h_NGoodVtx = N_Good_Vtx; 

if(pass_lepton_veto)h_pass_lepton_veto = 1;
else h_pass_lepton_veto = 0;

if(pass_jet_veto)h_pass_jet_veto =1;
else h_pass_jet_veto=0;

h_njet = jet_index_met.size();
h_nbjet = njet_b;
h_nhjet = njet_highpt;
h_jjdr = jjdr;

fFile->cd();
m_tree->Fill();

}//finish fill branches






   return kTRUE;
}

void physics::SlaveTerminate()
{
   // The SlaveTerminate() function is called after all entries or objects
   // have been processed. When running with PROOF SlaveTerminate() is called
   // on each slave server.

}

void physics::Terminate()
{
   // The Terminate() function is the last function to be called during
   // a query. It always runs on the client, it can be used to present
   // the results graphically or save the results to file.

TString _option_term = Gen_Option;
if(_option_term.Contains("GenPile")){
string temp_name = MC_runNumber + ".prw.root"; 

cout<<"pile up write "<<temp_name<<endl;

m_pileupTool->WriteToFile(temp_name.c_str());
}

string outline[15]={"0 initial","1 htop","2 Nlepton>1 ","3 trigger","4 good vtx","5 metclean","6 Only 1 lepton","7 lepton veto","8 lepton veto","9 mt","10 met","11 2jet ","12 2jet eta","13 b>1","14 b=2"};
cout<<"====before output the egamma cutflow===="<<endl;
for(int i=0; i<15; i++){
cout<<count_egamma.at(i).first<<endl;
cout<<count_egamma.at(i).first<<endl;
}
cout<<"====before output the muon cutflow===="<<endl;
for(int i=0; i<15; i++){
cout<<count_muon.at(i).first<<endl;
cout<<count_muon.at(i).first<<endl;
}

fOut<<"====before output the egamma cutflow===="<<endl;
for(int i=0; i<15; i++){
fOut<<i<<"     "<<count_egamma.at(i).first<<endl;
}

fOut<<"====before output the muon cutflow===="<<endl;
for(int i=0; i<15; i++){
fOut<<i<<"     "<<count_muon.at(i).first<<endl;
}
fOut<<"====before output the total cutflow===="<<endl;
for(int i=0; i<15; i++){
if(i<3)fOut<<outline[i]<<"     "<<count_muon.at(i).first<<endl;
if(i>2)fOut<<outline[i]<<"     "<<count_muon.at(i).first + count_egamma.at(i).first<<endl;
}

fOut<<"count the electrons"<<endl; 
fOut<<"all "<<ic_all <<endl; 
fOut<<"author "<<ic_author<<endl;
fOut<<"tight "<<ic_tight<<endl;
fOut<<"et "<<ic_et<<endl;
fOut<<"eta "<<ic_eta<<endl;
fOut<<"d0 "<<ic_d0<<endl;
fOut<<"el_oq "<<ic_oq<<endl;
fOut<<"ptcone "<<ic_ptcone<<endl;
fOut<<"etcone "<<ic_etcone<<endl;
fOut<<"or "<<ic_or<<endl;
fOut<<"or2 "<<ic_or2<<endl;
fOut<<"all cut "<<ic_allcuts<<endl<<endl<<endl;


fOut<<"count the veto electrons "<<endl;
fOut<<"all "<<ic_veto_all <<endl;
fOut<<"author "<<ic_veto_author<<endl;
fOut<<"tight "<<ic_veto_tight<<endl;
fOut<<"et "<<ic_veto_et<<endl;
fOut<<"eta "<<ic_veto_eta<<endl;
fOut<<"d0 "<<ic_veto_d0<<endl;
fOut<<"el_oq "<<ic_veto_oq<<endl;
fOut<<"ptcone "<<ic_veto_ptcone<<endl;
fOut<<"etcone "<<ic_veto_etcone<<endl;
fOut<<"or "<<ic_veto_or<<endl;
fOut<<"or2 "<<ic_veto_or2<<endl;
fOut<<"all cut "<<ic_veto_allcuts<<endl<<endl<<endl;



fOut<<"count the muons"<<endl;
fOut<<"all       "<<icm_all<<endl;
fOut<<"tight       "<<icm_tight<<endl;
fOut<<"blayer       "<<icm_blayer<<endl;
fOut<<"pixel       "<<icm_pixel<<endl;
fOut<<"sct       "<<icm_sct<<endl;
fOut<<"pix sct hole       "<<icm_PixSCThole<<endl;
fOut<<"trt central       "<<icm_trtL<<endl;
fOut<<"trt outrange       "<<icm_trtH<<endl;
fOut<<"z0       "<<icm_z0<<endl;
fOut<<"d0       "<<icm_d0<<endl;
fOut<<"pt       "<<icm_pt<<endl;
fOut<<"eta       "<<icm_eta<<endl;
fOut<<"ptcone       "<<icm_ptcone<<endl;
fOut<<"etcone       "<<icm_etcone<<endl;
fOut<<"overlap       "<<icm_or<<endl;
fOut<<"all cut       "<<icm_allcut<<endl<<endl<<endl;

fOut<<"count the muons veto"<<endl;
fOut<<"all       "<<icm_veto_all<<endl;
fOut<<"tight       "<<icm_veto_tight<<endl;
fOut<<"blayer       "<<icm_veto_blayer<<endl;
fOut<<"pixel       "<<icm_veto_pixel<<endl;
fOut<<"sct       "<<icm_veto_sct<<endl;
fOut<<"pix sct hole       "<<icm_veto_PixSCThole<<endl;
fOut<<"trt central       "<<icm_veto_trtL<<endl;
fOut<<"trt outrange       "<<icm_veto_trtH<<endl;
fOut<<"z0       "<<icm_veto_z0<<endl;
fOut<<"d0       "<<icm_veto_d0<<endl;
fOut<<"pt       "<<icm_veto_pt<<endl;
fOut<<"eta       "<<icm_veto_eta<<endl;
fOut<<"ptcone       "<<icm_veto_ptcone<<endl;
fOut<<"etcone       "<<icm_veto_etcone<<endl;
fOut<<"overlap       "<<icm_veto_or<<endl;
fOut<<"all cut       "<<icm_veto_allcut<<endl<<endl<<endl;

fOut<<"count the jets"<<endl;
fOut<<"all           "<<icj_all<<endl;
fOut<<"e             "<<icj_e<<endl;
fOut<<"not bad loose     "<<icj_notbadloose<<endl;
fOut<<"not bad      "<<icj_notbad<<endl;
fOut<<"not ugly     "<<icj_notugly<<endl;
fOut<<"pt cut      "<<icj_pt<<endl;
fOut<<"eta 2.5     "<<icj_eta<<endl;
fOut<<"jvf             "<<icj_jvf<<endl;
fOut<<"or             "<<icj_or<<endl;
fOut<<"allcuts             "<<icj_allcuts<<endl<<endl<<endl;

fOut<<"count the veto jets"<<endl;
fOut<<"all           "<<icj_veto_all<<endl;
fOut<<"e             "<<icj_veto_e<<endl;
fOut<<"not bad loose     "<<icj_veto_notbadloose<<endl;
fOut<<"not bad      "<<icj_veto_notbad<<endl;
fOut<<"not ugly     "<<icj_veto_notugly<<endl;
fOut<<"pt cut      "<<icj_veto_pt<<endl;
fOut<<"eta 2.5     "<<icj_veto_eta<<endl;
fOut<<"jvf             "<<icj_veto_jvf<<endl;
fOut<<"or             "<<icj_veto_or<<endl;
fOut<<"allcuts             "<<icj_veto_allcuts<<endl<<endl<<endl;


fFile->cd();
m_tree->Write();
h_cutflow_eg_num->Write();
h_cutflow_eg_num_1->Write();
h_cutflow_eg_num_2->Write();

h_cutflow_eg_wei->Write();
h_cutflow_eg_wei_1->Write();
h_cutflow_eg_wei_2->Write();

h_cutflow_eg_elec->Write();
h_cutflow_eg_elec_1->Write();
h_cutflow_eg_elec_2->Write();


h_cutflow_mu_num->Write();
h_cutflow_mu_num_1->Write();
h_cutflow_mu_num_2->Write();

h_cutflow_mu_wei->Write();
h_cutflow_mu_wei_1->Write();
h_cutflow_mu_wei_2->Write();

h_cutflow_mu_muon->Write();
h_cutflow_mu_muon_1->Write();
h_cutflow_mu_muon_2->Write();

h_cutflow_jet->Write();
h_cutflow_jet_1->Write();
h_cutflow_jet_2->Write();


m_tree->SetDirectory(0);
fFile->Close();
}


//====================================//
vector<container> physics::get_electron_met(int myRunNumber, int kIsData, TString option, vector<container> jet, vector<container> muon){
   vector<container> elec_index;
   elec_index.clear();

  int N_e = el_n;

bool get_veto = false; //get veto electrons
if( option.Contains("veto") )get_veto = true;  
bool get_save = false; //get veto electrons
if( option.Contains("save") )get_save = true;  

eRescale.SetRandomSeed(EventNumber);

  for (Int_t i=0; i < N_e; i++){

    Double_t Pt_trk    = (*el_pt)[i];
    Double_t Eta_trk   = (*el_tracketa)[i];
    Double_t Phi_trk   = (*el_trackphi)[i];

    Double_t Pt        = (*el_cl_pt)[i];
    Double_t Eta       = (*el_cl_eta)[i];
    Double_t Eta_cluster = (*el_cl_eta)[i];
    Double_t Phi       = (*el_cl_phi)[i];
    Double_t Phi_cluster = (*el_cl_phi)[i];
    Double_t Ecluster  = (*el_cl_E)[i];

    Int_t ele_SCTHits = (*el_nSCTHits)[i];
    Int_t ele_PIXHits = (*el_nPixHits)[i];
    Int_t ele_Hits_SCTPIX = ele_PIXHits + ele_SCTHits ;

    Double_t d0           = el_trackd0pv->at(i); // D0 of el ID track given w.r.t. the primary vertex position (PV)
    Double_t z0           = el_trackz0pv->at(i); // Z0 of el ID track given w.r.t. the promary vertex position (PV)

    Double_t d0sig = (*el_tracksigd0pv)[i];
    Double_t z0sig = (*el_tracksigz0pv)[i];

    Double_t d0unb = 0; // D0 of el ID track; given w.r.t. the primary vertex (PV) position, computed removing the el track from the PV position fit 

   if(b_el_trackd0pvunbiased){
    d0unb = (*el_trackd0pvunbiased)[i];
   }
   else {
    d0unb = d0sig; 
   } 


    //Double_t sumet = (*el_Etcone30)[i];
    Double_t sumet = (*el_topoEtcone30)[i];
    Double_t sumpt = (*el_ptcone20)[i];

    Double_t Pt_orig      = Pt;             // original Pt from ECalo cluster measurements


     /* *******************************************************************
        *  For electron energy direction follows the recommendations in   *
        * https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/ElectronsEnergyDirection
        ******************************************************************* */
double Ecluster_Ori = Ecluster;
float  Et = Ecluster/cosh(Eta); 

        if(ele_Hits_SCTPIX > 3 && el_author->at(i)!=8){
	 Eta = Eta_trk;  // use ID tracker for eta, if possible.
         Phi = Phi_trk;  // use ID tracker for phi, if possible.
 	 Et = Ecluster/cosh(Eta);
	}
	else{
	Et = Pt; 
	} 

float Et_Ori = Et;

   bool mcWithConstantTerm=false;  // if you use a MC without constant term, set this parameter to false otherwise true
   double ele_delta_px = 0;
   double ele_delta_py = 0;
   double ele_cl_etx = 0.0;
   double ele_cl_ety = 0.0;

      ele_cl_etx = Ecluster/cosh(Eta)*cos(Phi);
      ele_cl_ety = Ecluster/cosh(Eta)*sin(Phi);

double E_up(0),E_down(0),Et_up(0),Et_down(0),Et_ori(0),E_Rup(0),E_Rdown(0),Et_Rup(0),Et_Rdown(0);

    if(kIsData){
     double E_new;
      E_new = eRescale.applyEnergyCorrectionMeV(Eta_cluster, Phi_cluster, Ecluster, Et, 0, "ELECTRON" );
     double correction = E_new/Ecluster;
     Et *= correction;
     Ecluster *= correction;	
   }  
   else{
	double er_up = -1; double er_down = -1;
	eRescale.getErrorMeV(Eta_cluster,Ecluster,er_up, er_down, "ELECTRON");
	E_up = Ecluster * ( 1+ er_up);
	E_down = Ecluster * ( 1- er_down);
	Et_up = Et * ( 1+ er_up);
	Et_down = Et * ( 1- er_down);

        double smearcorr = 1.;
        smearcorr = eRescale.getSmearingCorrectionMeV(Eta_cluster, Ecluster, 0, mcWithConstantTerm);
        Ecluster = Ecluster*smearcorr;
        Et = Et*smearcorr;
        double smearcorr_up   = eRescale.getSmearingCorrectionMeV(Eta_cluster, Ecluster, 2, mcWithConstantTerm);
        E_Rup = Ecluster*smearcorr_up;
        Et_Rup = Et*smearcorr_up;
        double smearcorr_down = eRescale.getSmearingCorrectionMeV(Eta_cluster, Ecluster, 1, mcWithConstantTerm);
        E_Rdown = Ecluster*smearcorr_down;
        Et_Rdown = Et*smearcorr_down;
     }//end smearing Et and the systematic studies
   
    //cout<<"check scale elec"<<Ecluster/Ecluster_Ori<<endl;
    if(kIsCutFlow){Ecluster = Ecluster_Ori; Et=Et_Ori;}//Here apply no smearing nor scaling 


     /* *******************************************************************
     * trig matching
     * ******************************************************************/
/*
     bool trig_match = false;
     int EFindex = -1;
     if(!kIsData){
     if ( PassedTriggerEF( el_tracketa->at(i) , el_trackphi->at(i) , trig_EF_el_EF_e60_medium1 , EFindex, trig_EF_el_n , trig_EF_el_eta , trig_EF_el_phi) ){
      cout << "Offline object matched to valid e60_loose trigger object" << endl;
      trig_match = true;
     }
    }
    else{
	trig_match = true;
    }	 
*/

    double pt_corrected = Ecluster/cosh(Eta);


        //flags to check the ET cut for both Signal and Veto
        bool ETCutSign = ( Et > ELE_EtCutSign);
        bool ETCutVeto = ( Et > ELE_EtCutVeto);

        if ( option.Contains("vetoNoRemove") ) ETCutVeto = ( Et > 15000 ); //Top remove jet that overlapped with loose electrons 


        //bool ETCutLoose = ( Et_down > ELE_EtCutVeto * 0.9);//Save 
        bool ETCutLoose = ( Et > 8000); 

  //flags to check the Eta cut for both Signal and Veto
        bool EtaCutSign = ( fabs(Eta_cluster) < ELE_EtaCutSign );
          // apply different eta cut for Author==8 in Veto el.
        bool EtaCutVeto = ( fabs(Eta_cluster) < ELE_EtaCutVeto );

  //flags to check the D0 cut for both Signal and Veto
        // for veto do not check the D0 for the forward electrons (author==8)
        // as we did for the isolation
        bool D0CutSign = (fabs(d0unb) < ELE_D0CutSign);
        bool D0CutVeto = (fabs(d0unb) < ELE_D0CutVeto) || el_author->at(i)==8;

        //flags to check the OQ cut for both Signal and Veto
        bool OQCutSign = ( ( el_OQ->at(i) & 1446 ) == ELE_OQCutSign );
        bool OQCutVeto = ( ( el_OQ->at(i) & 1446 ) == ELE_OQCutVeto );

  // flag to check the elctron author
        bool authorSign = false;   // == false if author is not correct
        bool authorVeto = false;   // == false if author is not correct

        // flag to check the electron Tight++ selection
        bool tightpp = false;    // == true if electron passes Tight++ selection
        bool tightPP = false;    // == true if electron passes Tight++ selection


        // flag to check the electron Loose++ and ForwardElectronLoose selection
        bool loosepp = false;    // == true if electron passes Loose++ selection
        bool isFrwdElectronLoose = false; // check needed only for author==8  (Veto)
        bool SelectVeto = false;



    float eta_is = (*el_etas2)[i];
    float et_is = (*el_cl_E)[i]/cosh(eta_is);
    float rhad_is = (*el_Ethad)[i]/et_is;
    float rhad1_is = (*el_Ethad1)[i]/et_is;
    float reta_is = (*el_reta)[i];
    float weta2_is = (*el_weta2)[i];
    float f1_is = (*el_f1)[i];
    float f3_is = (*el_f3)[i];
    float wstot_is = (*el_wstot)[i];
    float dEmaxS1_is =( (*el_emaxs1)[i] - (*el_Emax2)[i] )/ ((*el_emaxs1)[i] + (*el_Emax2)[i] );
    float deta_is = (*el_deltaeta1)[i];
    float dphi_is = (*el_deltaphi2)[i];
    float eoverp_is = (*el_cl_E)[i] * fabs((*el_trackqoverp)[i]);
    float d0_is = (*el_trackd0_physics)[i];
    float HTRatio_is = (*el_TRTHighTOutliersRatio)[i];
    int nTRT_is = (*el_nTRTHits)[i];
    int nTRTOutlier_is = (*el_nTRTOutliers)[i];
    int nSi_is = (*el_nSiHits)[i];
    int nSiOutliers_is = (*el_nSCTOutliers)[i] + (*el_nPixelOutliers)[i];
    int nPix_is = (*el_nPixHits)[i];
    int nSCT_is = (*el_nSCTHits)[i];
    int nPixOutlier_is = (*el_nPixelOutliers)[i];
    int nBlayer_is = (*el_nBLHits)[i];
    int nBlayerOutlier_is = (*el_nBLayerOutliers)[i]; 
    float expectBlayer_num = (*el_expectHitInBLayer)[i];
    bool expectBlayer_is = (expectBlayer_num>0)? true:false;
    int convBit_is = (*el_isEM)[i] & (1 << egammaPID::ConversionMatch_Electron);

            authorVeto = ( el_author->at(i)==1 || el_author->at(i)==3);

            loosepp = isLoosePlusPlus(eta_is, et_is, rhad_is, rhad1_is, reta_is,
                                      weta2_is, f1_is, wstot_is, dEmaxS1_is,
                                      deta_is, nSi_is, nSiOutliers_is,
                                      nPix_is, nPixOutlier_is);

            //isFrwdElectronLoose = ( (el_isEM->at(i) & egammaPID::frwdElectronLoose)==0 );
            isFrwdElectronLoose = (el_loose->at(i) );

            //SelectVeto =  loosepp ;  
            SelectVeto =  (loosepp && fabs(eta_is)<2.47) ;  

            // set the author flag
            authorSign = (el_author->at(i)!=1 && el_author->at(i)!=3)? false:true;

           tightPP =  isTightPlusPlus(eta_is, et_is, f3_is,
                        rhad_is, rhad1_is, reta_is, weta2_is,
                        f1_is, wstot_is, dEmaxS1_is, deta_is, d0_is,
                        HTRatio_is, nTRT_is, nTRTOutlier_is,
                        nSi_is, nSiOutliers_is, nPix_is, nPixOutlier_is,
                        nBlayer_is, nBlayerOutlier_is, expectBlayer_is, eoverp_is, dphi_is, convBit_is
                        );

	    if(kIsReverse){
	    tightpp = loosepp;
            }
	    else {	

           tightpp = (tightPP && fabs(eta_is)<2.47 ); 

           }
        //flags to check the sumpt/Et cut on both Signal and Veto
        // use absolute value of sumpt in order to remove unphysical
        // values for forward electrons, i.e. at |eta|>2.5.
        // Warning: cut should be sumPt/Pt, but pT==ET
	bool hastrack = (el_hastrack->at(i));
        bool SumPt_EtCutSign = (kIsReverse)?( true ):(( fabs(sumpt)/Et < ELE_SumPt_EtCutSign ) && hastrack);

        //for Veto electron apply the sumpt/Et cut only for E < 25 GeV .. removed
        // for veto do not check isolation for forward electrons (author==8)
        //bool SumPt_EtCutVeto = (kIsReverse)?( el_author->at(i)==8 || (fabs(sumpt)/Et > ELE_SumPt_EtCutVeto) ):( el_author->at(i)==8 || (fabs(sumpt)/Et < ELE_SumPt_EtCutVeto) );
        bool SumPt_EtCutVeto = (kIsReverse)?( true ):( (fabs(sumpt)/Et < ELE_SumPt_EtCutVeto) );

        //flags to check the sumEt/Et on both Signal and Veto
        // use the nPV pileup correction + pT leakege
        Int_t nVtx = 0;

    for (Int_t pv=0;pv<vxp_n;pv++) {
        if( vxp_nTracks->at(pv) >= 2 ) nVtx++;
    }

        bool is_mc = !kIsData;
/*
        float sumet_corrected = CaloIsoCorrection::GetPtNPVCorrectedIsolation(nVtx,
                                    el_cl_E->at(i),
                                    el_etas2->at(i),
                                    el_CaloPointing_eta->at(i),
                                    el_cl_eta->at(i),
                                    30,is_mc,sumet,false,
                                    CaloIsoCorrection::ELECTRON);
*/
        float sumet_corrected = CaloIsoCorrection::GetPtEDCorrectedTopoIsolation(el_ED_median->at(i),
                                    el_cl_E->at(i),
                                    el_etas2->at(i),
                                    el_CaloPointing_eta->at(i),
                                    el_cl_eta->at(i),
                                    30,is_mc,sumet,false,
                                    CaloIsoCorrection::ELECTRON);



        //bool SumEt_EtCutSign =  (kIsReverse)?( (sumet_corrected/Et > ELE_SumEt_EtCutSign)  && (sumet_corrected/Et < 0.6) ):( sumet_corrected/Et < ELE_SumEt_EtCutSign );
        //bool SumEt_EtCutVeto =  (kIsReverse)?( (sumet_corrected/Et > ELE_SumEt_EtCutVeto)  && (sumet_corrected/Et < 0.6) ):( sumet_corrected/Et < ELE_SumEt_EtCutVeto ) ;

        bool SumEt_EtCutSign =  (kIsReverse)?( true ):( sumet_corrected/Et < ELE_SumEt_EtCutSign );
        bool SumEt_EtCutVeto =  (kIsReverse)?( true ):( sumet_corrected/Et < ELE_SumEt_EtCutVeto ) ;


        //flags checking the overlap removal among electrons and veto jets
        bool OVLJetRemoveSign = false; // == true if electron must be removed
        bool OVLJetRemoveVeto = false; // == true if electron must be removed

        if ( option.Contains("RemoveOVLJ") ) {
            // veto candidates are jets
        for(std::vector<container>::iterator j = jet.begin(); j < jet.end(); j++) {
                double eta_j = j->tlv.Eta();
                double phi_j = j->tlv.Phi();
                double deta = caldeta(Eta, eta_j);
                double dphi = caldphi(Phi, phi_j);
                if (Et < 15000) {
                     if(caldr(deta,dphi)<0.4){ 
                        OVLJetRemoveSign=true;
                  } 
                }
            }
        }


         //flags checking the overlap removal among electrons and muons
        bool OVLMuonRemoveSign = false; // == true if electron must be removed
        bool OVLMuonRemoveVeto = false; // == true if electron must be removed
        if ( option.Contains("RemoveOVLM") ) {
            // veto candidates are muons
        for(std::vector<container>::iterator m = muon.begin(); m < muon.end(); m++) {
                double eta_m = m->tlv.Eta();
                double phi_m = m->tlv.Phi();
                double deta = caldeta(Eta, eta_m);
                double dphi = caldphi(Phi, phi_m);
                 if(caldr(deta,dphi)<0.2)OVLMuonRemoveSign=true;
            }
        }

//Remove overlap from muon & jet for both veto/signal eles; however, signal jet all pt>25GeV, so not necessary to do the overlap remove for signal electron.


bool pass_veto_pt_cut = ETCutVeto;
bool pass_signal_pt_cut = ETCutSign;
bool pass_save_pt_cut =ETCutLoose;

bool pass_signal_except_pt =false;

if(get_save){
   if(!pass_save_pt_cut)continue;
   //if(!(authorVeto && SelectVeto && EtaCutVeto && OQCutVeto && SumPt_EtCutVeto && (!OVLMuonRemoveSign) && (!OVLJetRemoveSign)))continue;
   if(!(authorVeto && SelectVeto && EtaCutVeto && D0CutSign && OQCutVeto && (!OVLMuonRemoveSign) && (!OVLJetRemoveSign)))continue;//No sumpt cut ,for isolation
   if(authorSign && tightpp && EtaCutSign && D0CutSign && OQCutSign && SumPt_EtCutSign && SumEt_EtCutSign && (!OVLMuonRemoveSign) && (!OVLJetRemoveSign))pass_signal_except_pt=true;
}


  if(!get_veto && option.Contains("RemoveOVLM") && !get_save){
  if(authorSign && tightpp && EtaCutSign && D0CutSign && OQCutSign && SumPt_EtCutSign && SumEt_EtCutSign && (!OVLMuonRemoveSign) && (!OVLJetRemoveSign))pass_signal_except_pt=true;
   h_cutflow_eg_elec->Fill(1); 
   if(authorSign) h_cutflow_eg_elec->Fill(2); 
   if(tightpp)  h_cutflow_eg_elec->Fill(3);
   if(ETCutSign) h_cutflow_eg_elec->Fill(4);
   if(EtaCutSign) h_cutflow_eg_elec->Fill(5);
   if(D0CutSign) h_cutflow_eg_elec->Fill(6);
   if(OQCutSign) h_cutflow_eg_elec->Fill(7);
   if(SumPt_EtCutSign) h_cutflow_eg_elec->Fill(8);
   if(SumEt_EtCutSign) h_cutflow_eg_elec->Fill(9);
   if(!OVLMuonRemoveSign) h_cutflow_eg_elec->Fill(10); 
   if(!OVLJetRemoveSign) h_cutflow_eg_elec->Fill(11); 
   if( (!OVLMuonRemoveSign) && (!OVLJetRemoveSign)) h_cutflow_eg_elec->Fill(12);
   if(authorSign && tightpp && ETCutSign && EtaCutSign && D0CutSign && OQCutSign && SumPt_EtCutSign && SumEt_EtCutSign) h_cutflow_eg_elec->Fill(13);
   if(authorSign && tightpp && ETCutSign && EtaCutSign && D0CutSign && OQCutSign && SumPt_EtCutSign && SumEt_EtCutSign && (!OVLJetRemoveSign)) h_cutflow_eg_elec->Fill(14);
   if(authorSign && tightpp && ETCutSign && EtaCutSign && D0CutSign && OQCutSign && SumPt_EtCutSign && SumEt_EtCutSign && (!OVLMuonRemoveSign) && (!OVLJetRemoveSign)) h_cutflow_eg_elec->Fill(15);
   else continue;
   } 

   if(get_veto && option.Contains("RemoveOVLM") && !get_save){
   h_cutflow_eg_elec_1->Fill(1);
   if(authorVeto)h_cutflow_eg_elec_1->Fill(2); 
   if(SelectVeto)h_cutflow_eg_elec_1->Fill(3); 
   if(ETCutVeto) h_cutflow_eg_elec_1->Fill(4);
   if(EtaCutVeto) h_cutflow_eg_elec_1->Fill(5);
   if(OQCutVeto) h_cutflow_eg_elec_1->Fill(7);
   if(SumPt_EtCutVeto) h_cutflow_eg_elec_1->Fill(8);
   if((!OVLMuonRemoveVeto)) h_cutflow_eg_elec_1->Fill(10);
   if((!OVLJetRemoveVeto)) h_cutflow_eg_elec_1->Fill(11);
   if((!OVLMuonRemoveVeto) && (!OVLJetRemoveVeto)) h_cutflow_eg_elec_1->Fill(12);
   if(authorVeto && SelectVeto && ETCutVeto && EtaCutVeto && OQCutVeto && SumPt_EtCutVeto ) h_cutflow_eg_elec_1->Fill(13);
   if(authorVeto && SelectVeto && ETCutVeto && EtaCutVeto && OQCutVeto && SumPt_EtCutVeto && D0CutSign) h_cutflow_eg_elec_1->Fill(16);
   if(authorVeto && SelectVeto && ETCutVeto && EtaCutVeto && OQCutVeto && SumPt_EtCutVeto && D0CutSign && (!OVLJetRemoveSign)) h_cutflow_eg_elec_1->Fill(17);
   if(authorVeto && SelectVeto && ETCutVeto && EtaCutVeto && OQCutVeto && SumPt_EtCutVeto && D0CutSign && (!OVLJetRemoveSign)) h_cutflow_eg_elec_1->Fill(14);        //Acturally, overlap removal is same for both  signal and veto, if will only be true for electron<20GeV, which means always pass the removal for signal.
   if(authorVeto && SelectVeto && ETCutVeto && EtaCutVeto && OQCutVeto && SumPt_EtCutVeto && D0CutSign && (!OVLMuonRemoveSign) && (!OVLJetRemoveSign)) h_cutflow_eg_elec_1->Fill(15);  //Acturally, overlap removal is same for both  signal and veto, if will only be true for electron<20GeV, which means always pass the removal for signal.
   else continue;
   } 

   if(get_veto && option.Contains("NoRemove") && !get_save){
   if (!(authorVeto && SelectVeto && ETCutVeto && EtaCutVeto && OQCutVeto && SumPt_EtCutVeto && D0CutSign)) continue;
   }




container t_tmp;
   double _recSF = 1;
   double _eidSF = 1;
   double _recSF_err = 0;
   double _eidSF_err = 0;

   if(!kIsData){
    float cl_eta = (*el_cl_eta)[i];
    if(fabs(cl_eta)<2.47 && pt_corrected>25000){
    
    std::pair<float,float> reco_sf = egSF->scaleFactor(cl_eta,pt_corrected,4,0,8,true,myRunNumber);
    std::pair<float,float> id_sf = egSF->scaleFactor(cl_eta,pt_corrected,7,0,8,true,myRunNumber);//7 means tight++

    std::pair<float,float> trig_sf_e20 = egSF->scaleFactor(cl_eta,pt_corrected,35,0,8,true,myRunNumber);//10 means tight++ for e20_medium trigger
    std::pair<float,float> trig_sf_e22 = egSF->scaleFactor(cl_eta,pt_corrected,35,0,8,true,myRunNumber);//14 means tight++ for e22_medium trigger
    std::pair<float,float> trig_sf_e22vh = egSF->scaleFactor(cl_eta,pt_corrected,35,0,8,true,myRunNumber);//18 means tight++ for e22vh_medium trigger

    if(option.Contains("recSFUp")) _recSF = (reco_sf.first + reco_sf.second); 
    else if(option.Contains("recSFDown")) _recSF = (reco_sf.first - reco_sf.second); 
    else _recSF = reco_sf.first;
    _recSF_err=reco_sf.second;

    if(option.Contains("recSFUp")){ _eidSF = (id_sf.first - id_sf.second);}
    else if(option.Contains("recSFDown")){_eidSF = (id_sf.first + id_sf.second);}
    else _eidSF = id_sf.first;
     _eidSF_err = id_sf.second;

if(RunNumber == 180164){
   t_tmp.trigsf_e20   = trig_sf_e20.first;
}
else if(RunNumber == 183003){
   t_tmp.trigsf_e20   = trig_sf_e20.first;
}
else if(RunNumber == 189751){
   t_tmp.trigsf_e20   = trig_sf_e22vh.first;
}
else if(RunNumber == 186169){
   if( count_number%10<3){
    t_tmp.trigsf_e20   = trig_sf_e20.first;
   }//I 337.543 pb-1 about30% //so I take 3 number(0,1,2) out of 10 numbers(0-9)  
   else{
    t_tmp.trigsf_e20   = trig_sf_e20.first;
   }//JK 226.392 pb-1+590.363 pb-1 = 816.755 //roughly half to half
} 

    //t_tmp.trigsf_e20   = trig_sf_e20.first;
    t_tmp.trigsf_e22   = trig_sf_e22.first;
    t_tmp.trigsf_e22vh = trig_sf_e22vh.first;
    }
    else{
    t_tmp.trigsf_e20   = 1.0;
    t_tmp.trigsf_e22   = 1.0;
    t_tmp.trigsf_e22vh = 1.0;
   }

   }

    t_tmp.tlv.SetPtEtaPhiM(Et,Eta,Phi,0.511);//Use Et here//For electrons, here Et is well calculated,Do not need another pt. 
    t_tmp.index  = i;
    t_tmp.author  = (*el_author)[i];
    t_tmp.SumEt   = sumet_corrected;
    t_tmp.SumPt   = sumpt;
    t_tmp.D0      = d0unb;
    t_tmp.D0sig   = d0sig;
    t_tmp.Z0      = (*el_trackz0pv)[i];
    t_tmp.Z0sig   = z0sig;
    t_tmp.NBLayer = (*el_nBLHits)[i]  ;
    t_tmp.NPixel  = ele_PIXHits ;
    t_tmp.NSCT    = ele_SCTHits ;
    t_tmp.NTRT    = (*el_nTRTHits)[i] ;
    t_tmp.charge       = (*el_charge)[i];
    t_tmp.pdgID   = t_tmp.charge*11.;
    t_tmp.pt   = Et;
    t_tmp.pt_ori   = Et_ori;
    t_tmp.eta   = Eta;
    t_tmp.phi   = Phi;
    t_tmp.Et   = Et;
    t_tmp.E   = t_tmp.tlv.E();
    t_tmp.sf   = _eidSF;
    t_tmp.sf_err = _eidSF_err;
    t_tmp.rec_sf = _recSF;
    t_tmp.rec_sf_err = _recSF_err;
    t_tmp.pass_looseptcut = pass_veto_pt_cut;
    t_tmp.pass_tightptcut = pass_signal_pt_cut;
    t_tmp.pass_tightcut = pass_signal_except_pt; 
    t_tmp.Et_up = Et_up;
    t_tmp.Et_down = Et_down;
    t_tmp.Et_Rup = Et_Rup;
    t_tmp.Et_Rdown = Et_Rdown;

    long  IsEM = (*el_isEM)[i];
    float eta2 = (*el_etas2)[i];
    float Reta = (*el_reta)[i] ;
    float w2   = (*el_weta2)[i];

    if( tightPP )  t_tmp.isTight = true;
    else t_tmp.isTight =  false;
    if(  (egammaPID::ElectronMedium & (*el_isEM)[i] ) == 0  ) t_tmp.isMedium= true;
    else t_tmp.isMedium=  false;
    if( loosepp  ) t_tmp.isLoose = true;
    else t_tmp.isLoose = false;

    if(isFrwdElectronLoose) t_tmp.frwdLoose = true;
    else t_tmp.frwdLoose = false;

   // if( !t_tmp.IsTight) continue;

    ////////////////Save the change on px and py for late MET calculation
    t_tmp.pxCorr   = ele_delta_px;
    t_tmp.pyCorr   = ele_delta_py;
   elec_index.push_back(t_tmp);

   }


  if(elec_index.size()>0){
  std::sort(elec_index.begin(),elec_index.end());
  std::reverse(elec_index.begin(),elec_index.end());
  }


  return elec_index;
}

vector<container> physics::get_muon_met(int myRunNumber, int kIsData, TString option, vector<container> jet){
  vector<container> muon_index;
  muon_index.clear();

bool get_veto = false; //get veto electrons
bool get_save = false; //get veto electrons
bool get_noncalo = false; //get veto electrons
if( option.Contains("veto") )get_veto = true;
if( option.Contains("save") )get_save = true;
if( option.Contains("noncalo") )get_noncalo = true;

  int N_m = mu_muid_n;


  for (Int_t i=0; i < N_m; i++){

  bool f_tight = true;
  bool f_blayer = true;
  bool f_pix = true;
  bool f_sct = true;
  bool f_holes = true;
  bool f_trt = true;
  bool f_z0 = true;
  bool f_d0 = true;
  bool f_pt = true;
  bool f_eta = true;
  bool f_ptcone = true;
  bool f_or = true;

  bool f_tight_veto = true;
  bool f_blayer_veto = true;
  bool f_pix_veto = true; 
  bool f_sct_veto = true;
  bool f_holes_veto = true;
  bool f_trt_veto = true;
  bool f_z0_veto = true;
  bool f_d0_veto = true;
  bool f_pt_veto = true;
  bool f_eta_veto = true;
  bool f_ptcone_veto = true;
  bool f_or_veto = true;


    Double_t    Pt = (*mu_muid_pt)[i];
    Double_t   Eta = (*mu_muid_eta)[i];
    Double_t   Phi = (*mu_muid_phi)[i];

    Double_t d0 = (*mu_muid_trackd0)[i] ;
    Double_t z0 = (*mu_muid_trackz0)[i] ;

    //Double_t d0unb = mu_muid_trackd0pvunbiased->at(i);
    //Double_t z0unb = mu_muid_trackz0pvunbiased->at(i);

    Double_t sumpt = (*mu_muid_ptcone20)[i];
    Double_t sumet = (*mu_muid_etcone30)[i];

    Double_t Theta_MS = (*mu_muid_me_theta)[i];
    Double_t Theta_ID = (*mu_muid_id_theta)[i];

    Double_t Charge = (*mu_muid_charge)[i];

    Double_t Pt_MS =  0; 
    if((*mu_muid_me_qoverp_exPV)[i]!=0) Pt_MS = fabs( (1.0 / (*mu_muid_me_qoverp_exPV)[i]) * sin( (*mu_muid_me_theta_exPV)[i])) ;
    Double_t Pt_ID =  0;
    if((*mu_muid_ie_qoverp_exPV)[i]!=0) Pt_ID = fabs( (1.0 / (*mu_muid_ie_qoverp_exPV)[i]) * sin( (*mu_muid_ie_theta_exPV)[i])) ;

    Int_t n_TRT_hit = (*mu_muid_nTRTHits)[i];
    Int_t n_TRT_out = (*mu_muid_nTRTOutliers)[i];
    Int_t n_TRT_tot = n_TRT_hit + n_TRT_out;

    Double_t mud0 = 0;
    Double_t muz0 = 0; 
    if(b_mu_muid_trackd0pvunbiased)mud0 = (*mu_muid_trackd0pvunbiased)[i];
    else mud0 = (*mu_muid_d0_exPV)[i];
    if(b_mu_muid_trackz0pvunbiased)muz0 = (*mu_muid_trackz0pvunbiased)[i];
    else  muz0 = (*mu_muid_z0_exPV)[i];

    Double_t mu_IDtrack_eta = -log (tan (Theta_ID/2.));


     //flags to define the muon type
     //bool isTight = (kIsReverse)? ((mu_muid_medium->at(i)==1)? true : false) : ((mu_muid_tight->at(i)==1)? true : false);
     bool isTight = (kIsReverse)? ((mu_muid_loose->at(i)==1)? true : false) : ((mu_muid_tight->at(i)==1)? true : false);
     bool isLoose = (mu_muid_loose->at(i)==1)? true : false;
     bool isMedium= (mu_muid_medium->at(i)==1)? true : false;

     //bool isStandalone = (mu_muid_isStandAloneMuon->at(i)==1 && fabs(Eta)>2.5)? true : false;
     bool isStandalone = false;
     isStandalone = ( (mu_muid_isStandAloneMuon->at(i)==1) || (mu_muid_isSiliconAssociatedForwardMuon->at(i)==1) )? true : false;
     //if(kIsData ||!kIsData ) isStandalone = ( (mu_muid_isStandAloneMuon->at(i)==1) )? true : false;//Only temp, will add the same to MC.
     bool applyStandaloneIdCut = (isStandalone)? true : false;

     bool isLargeEta = (fabs(Eta)>2.5) ? true : false;

    ////////////smearing the MC samples
     double Pt_Orignal = Pt;
     double pT_smeared =Pt;
     double pT_smeared_ms_up =Pt;
     double pT_smeared_ms_down =Pt;
     double pT_smeared_id_up =Pt;
     double pT_smeared_id_down =Pt;
     double pT_IDsmeared =Pt;
     double pT_IDsmeared_ms_up =Pt;
     double pT_IDsmeared_ms_down =Pt;
     double pT_IDsmeared_id_up =Pt;
     double pT_IDsmeared_id_down =Pt;
     double pT_MSsmeared =Pt;
     double pT_MSsmeared_ms_up =Pt;
     double pT_MSsmeared_ms_down =Pt;
     double pT_MSsmeared_id_up =Pt;
     double pT_MSsmeared_id_down =Pt;



    if(!kIsData && (Pt_MS !=0) && (Pt_ID != 0 )){
      mcp_smear_muid->SetSeed(EventNumber,i);
      mcp_smear_muid ->Event(Pt_MS, Pt_ID, Pt, Eta, Charge);
        // Get Smeared Pts

      double pt_tmp1(0),pt_tmp2(0);
      pT_smeared = mcp_smear_muid->pTCB();
      pT_IDsmeared = mcp_smear_muid->pTID();
      pT_MSsmeared = mcp_smear_muid->pTMS();

      mcp_smear_muid->PTVar(pT_MSsmeared_id_down,pT_IDsmeared_id_down,pT_smeared_id_down,"IDLOW");
      mcp_smear_muid->PTVar(pT_MSsmeared_id_up,pT_IDsmeared_id_up,pT_smeared_id_up,"IDUP");
      mcp_smear_muid->PTVar(pT_MSsmeared_ms_down,pT_IDsmeared_ms_down,pT_smeared_ms_down,"MSLOW");
      mcp_smear_muid->PTVar(pT_MSsmeared_ms_up,pT_IDsmeared_ms_up,pT_smeared_ms_up,"MSUP");

    //cout<<"pT smeared "<<pT_smeared<<"  " << i << "  "<<EventNumber<<"   "<<Pt<<"  "<<Eta<<"  "<<Charge<<"  "<<Pt_MS<<"  "<<Pt_ID<<endl;
    }

     Pt = pT_smeared;  
     if(kIsCutFlow)Pt=Pt_Orignal;//which means smear is now not activated
     Double_t muo_delta_px = (Pt - Pt_Orignal)*cos(Phi); //change on the px and py for MET recalculation
     Double_t muo_delta_py = (Pt - Pt_Orignal)*sin(Phi);

        // flags for the BLayer cuts
        // reminder: for the Veto object selection we apply a further cut
        // on |eta| < 2.5 only for counting the statistics
        bool BLayerForSign =
            ((!mu_muid_expectBLayerHit->at(i))|| mu_muid_nBLHits->at(i)>0);
        bool BLayerForVeto = 
            ((!mu_muid_expectBLayerHit->at(i))|| mu_muid_nBLHits->at(i)>0);

        // flags for Pixel cuts
        bool PixelForSign =
           (( mu_muid_nPixHits->at(i) +  mu_muid_nPixelDeadSensors->at(i) )>0);
        bool PixelForVeto = 
           (( mu_muid_nPixHits->at(i) +  mu_muid_nPixelDeadSensors->at(i) )>0);

        // flags for SCT cuts
        bool SCTForSign =
           ( (  mu_muid_nSCTHits->at(i) +  mu_muid_nSCTDeadSensors->at(i) )>4);
        bool SCTForVeto = 
           ( (  mu_muid_nSCTHits->at(i) +  mu_muid_nSCTDeadSensors->at(i) )>4);

        // flags for PixSCTHoles cuts
        bool PixSCTHolesForSign =
            ( (  mu_muid_nPixHoles->at(i) +  mu_muid_nSCTHoles->at(i) ) < 3);
        bool PixSCTHolesForVeto = 
            ( (  mu_muid_nPixHoles->at(i) +  mu_muid_nSCTHoles->at(i) ) < 3);

        // flags for TRT low eta cuts (|eta|<1.9)
        bool TRTloEtaForSign = (fabs(mu_IDtrack_eta)>=1.9 || fabs(mu_IDtrack_eta)<=0.1 ) ||
        (fabs(mu_IDtrack_eta)<1.9 && fabs(mu_IDtrack_eta)>0.1 && (n_TRT_tot>5 && (n_TRT_out < 0.9*n_TRT_tot)) );
        bool TRTloEtaForVeto = (fabs(mu_IDtrack_eta)>=1.9 || fabs(mu_IDtrack_eta)<=0.1 ) || 
        (fabs(mu_IDtrack_eta)<1.9 && fabs(mu_IDtrack_eta)>0.1 && (n_TRT_tot>5 && (n_TRT_out < 0.9*n_TRT_tot)) );

        // flags for TRT high eta cuts
        bool TRThiEtaForSign = ( (fabs(mu_IDtrack_eta)<1.9 && fabs(mu_IDtrack_eta)>0.1 ) ||
                                (n_TRT_tot<=5 || (n_TRT_out < 0.9*n_TRT_tot)) );
        //bool TRTnewSign      = !(fabs(mu_IDtrack_eta)<1.9 && (n_TRT_tot<=5 || n_TRT_out>=0.9*n_TRT_tot));
        bool TRThiEtaForVeto = ( (fabs(mu_IDtrack_eta)<1.9 && fabs(mu_IDtrack_eta)>0.1 ) || 
                                (n_TRT_tot<=5 || (n_TRT_out < 0.9*n_TRT_tot)) );


        // flags to check the Z0 cut for both signal and veto.
        // for veto check Z0 only for |eta| <2.47
        bool Z0CutForSign = (fabs(muz0) < MUO_Z0CutSign);
        bool Z0CutForVeto = (fabs(muz0) < MUO_Z0CutSign); 


        // flags to check the Z0 cut for both signal and veto.
        // for veto check the Z0 only for |eta| < 2.47
        bool D0CutForSign = (fabs(mud0) < MUO_D0CutSign);
        //bool D0CutForVeto = (applyStandaloneIdCut)? (fabs(mud0) < MUO_D0StandaloneCutVeto) : (fabs(mud0) < MUO_D0CutVeto);
        bool D0CutForVeto = (fabs(mud0) < MUO_D0CutVeto);


        // flags to check the Pt cut for both signal and veto.
        bool PtCutForSign = (Pt > MUO_PtCutSign);
        bool PtCutForVeto = (Pt > MUO_PtCutVeto);
        bool PtCutForVeto_SA = (Pt > 10000);

	bool PtCutForSave = (Pt > 8000);


        // flags to check the |eta| cut for both signal and veto.
        bool EtaCutForSign = (fabs(Eta) < MUO_EtaCutSign);
        bool EtaCutForVeto = (fabs(Eta) < MUO_EtaCutVeto);
        bool EtaCutForVeto_SA = (fabs(Eta) < 2.7) && (fabs(Eta) > 2.5);


        // flags to check the sumpT/pT cut for both signal and veto.
        bool SumpT_pTCutForSign = (kIsReverse)?(true):(sumpt/Pt < MUO_SumpT_pTCutSign);
        bool SumpT_pTCutForVeto = (kIsReverse)?(true):(sumpt/Pt < MUO_SumpT_pTCutVeto);

        // Compute the calo isolation but correct for NPv pileup effect
        CorrectCaloIso muonIsoTool;
        Int_t nVtx = 0;
               
    for (Int_t pv=0;pv<vxp_n;pv++) {
        if( vxp_nTracks->at(pv) >= 3 ) nVtx++;
    }
        string muonIso_option = "cone30Comb2012"; 
        float etcone30Rel = sumet/Pt;
        float etconecor30Rel = muonIsoTool.CorrectEtConeRel(Pt,etcone30Rel,nVtx,Eta,muonIso_option);

        //float etcone30Rel = sumet/Pt;
        //float etconecor30Rel = muonIsoTool.CorrectEtCone30Rel(Pt,etcone30Rel,nVtx,Eta);


        // flags to check the sumET/ET cut for both signal and veto
        //bool SumET_ETCutForSign = (kIsReverse)?((etconecor30Rel > MUO_SumET_ETCutSign) && (etconecor30Rel < 0.6)):( etconecor30Rel < MUO_SumET_ETCutSign );
        //bool SumET_ETCutForVeto = (kIsReverse)?((etconecor30Rel > MUO_SumET_ETCutSign) && (etconecor30Rel < 0.6)):( etconecor30Rel < MUO_SumET_ETCutVeto );

        bool SumET_ETCutForSign = (kIsReverse)?(true):( etconecor30Rel < MUO_SumET_ETCutSign );
        bool SumET_ETCutForVeto = (kIsReverse)?(true):( etconecor30Rel < MUO_SumET_ETCutVeto );

    bool OVLMuoRemoveSign = false;
    bool OVLMuoRemoveVeto = false;
    double minDR=0.4;
      if(jet.size() > 0)  {
        for(std::vector<container>::iterator j = jet.begin(); j < jet.end(); j++) {
           double _dphi = caldphi(Phi, j->tlv.Phi());
           double _deta = caldeta(Eta, j->tlv.Eta());
          if(caldr(_dphi, _deta)<minDR) OVLMuoRemoveSign = true;
          if(caldr(_dphi, _deta)<minDR) OVLMuoRemoveVeto = true;
        }
      }


////================================after the new update============================================================
bool MCPHitsVeto = (BLayerForVeto && PixelForVeto && SCTForVeto && PixSCTHolesForVeto && TRTloEtaForVeto && TRThiEtaForVeto && !applyStandaloneIdCut);
bool isMuidVeto = (isTight && MCPHitsVeto && PtCutForVeto && EtaCutForVeto && SumpT_pTCutForVeto && D0CutForVeto && Z0CutForVeto) ;
bool isMuidVeto_noTrackIso = (isTight && MCPHitsVeto && PtCutForVeto && EtaCutForVeto && D0CutForVeto && Z0CutForVeto ) ;
bool isSAVeto = (applyStandaloneIdCut && PtCutForVeto_SA && EtaCutForVeto_SA && isTight );

bool Pass_tight = false;
if(get_save){
if(!PtCutForSave)continue;
//if( (!(isMuidVeto_noTrackIso && (!OVLMuoRemoveVeto)))  && (!(isSAVeto  &&  (!OVLMuoRemoveVeto)))  )continue;//if not veto muid nor calo
if( (!(isMuidVeto_noTrackIso ))  && (!(isSAVeto  ))  )continue;//if not veto muid nor calo
if(isTight && BLayerForSign && PixelForSign && SCTForSign && PixSCTHolesForSign && TRTloEtaForSign && TRThiEtaForSign && Z0CutForSign && D0CutForSign && PtCutForSign && EtaCutForSign && SumpT_pTCutForSign && SumET_ETCutForSign  &&  (!OVLMuoRemoveVeto) )Pass_tight=true;
}



if(get_veto && !get_save && !get_noncalo){
h_cutflow_mu_muon_1->Fill(1);
if(isTight && !applyStandaloneIdCut) h_cutflow_mu_muon_1->Fill(2); 
if(!applyStandaloneIdCut) h_cutflow_mu_muon_1->Fill(3); 
if(BLayerForVeto  && !applyStandaloneIdCut ) h_cutflow_mu_muon_1->Fill(4);
if(PixelForVeto && !applyStandaloneIdCut) h_cutflow_mu_muon_1->Fill(5);
if(SCTForVeto && !applyStandaloneIdCut) h_cutflow_mu_muon_1->Fill(6);
if(PixSCTHolesForVeto && !applyStandaloneIdCut) h_cutflow_mu_muon_1->Fill(7);
if(TRTloEtaForVeto && !applyStandaloneIdCut) h_cutflow_mu_muon_1->Fill(8);
if(TRThiEtaForVeto && !applyStandaloneIdCut) h_cutflow_mu_muon_1->Fill(9);
if(TRThiEtaForVeto && TRTloEtaForVeto && !applyStandaloneIdCut ) h_cutflow_mu_muon_1->Fill(10);
if(MCPHitsVeto) h_cutflow_mu_muon_1->Fill(11);
if(PtCutForVeto && !applyStandaloneIdCut) h_cutflow_mu_muon_1->Fill(12);
if(EtaCutForVeto && !applyStandaloneIdCut) h_cutflow_mu_muon_1->Fill(13);
if(SumpT_pTCutForVeto && !applyStandaloneIdCut) h_cutflow_mu_muon_1->Fill(14);
if(!OVLMuoRemoveVeto) h_cutflow_mu_muon_1->Fill(15);
if( isMuidVeto ) h_cutflow_mu_muon_1->Fill(16);
if( isMuidVeto  &&  (!OVLMuoRemoveVeto) ) h_cutflow_mu_muon_1->Fill(17);

if(applyStandaloneIdCut) h_cutflow_mu_muon_1->Fill(18);
if(isMedium && applyStandaloneIdCut) h_cutflow_mu_muon_1->Fill(19);
if(PtCutForVeto_SA && applyStandaloneIdCut)h_cutflow_mu_muon_1->Fill(20);
if(EtaCutForVeto_SA && applyStandaloneIdCut)h_cutflow_mu_muon_1->Fill(21);
if( isSAVeto ) h_cutflow_mu_muon_1->Fill(22);
if( isSAVeto  &&  (!OVLMuoRemoveVeto) ) h_cutflow_mu_muon_1->Fill(23);

if( (isMuidVeto ) && Z0CutForSign && D0CutForSign)h_cutflow_mu_muon_1->Fill(26);
if( isSAVeto)h_cutflow_mu_muon_1->Fill(26);

if( (isMuidVeto ) && Z0CutForSign && D0CutForSign && (!OVLMuoRemoveVeto) )h_cutflow_mu_muon_1->Fill(27);
if( isSAVeto && (!OVLMuoRemoveVeto) )h_cutflow_mu_muon_1->Fill(27);

if( (isMuidVeto || isSAVeto ) && (!OVLMuoRemoveVeto) )h_cutflow_mu_muon_1->Fill(25);
if( (isMuidVeto || isSAVeto ) )h_cutflow_mu_muon_1->Fill(24);
else continue;
}


if(!get_veto && !get_save && !get_noncalo){
if(isTight && BLayerForSign && PixelForSign && SCTForSign && PixSCTHolesForSign && TRTloEtaForSign && TRThiEtaForSign && Z0CutForSign && D0CutForSign && EtaCutForSign && SumpT_pTCutForSign && SumET_ETCutForSign  &&  (!OVLMuoRemoveVeto) )Pass_tight=true;
h_cutflow_mu_muon->Fill(1);
if(  isTight)h_cutflow_mu_muon->Fill(2); 
if(  BLayerForSign && !applyStandaloneIdCut) h_cutflow_mu_muon->Fill(3);
if(  PixelForSign && !applyStandaloneIdCut) h_cutflow_mu_muon->Fill(4);
if(  SCTForSign && !applyStandaloneIdCut) h_cutflow_mu_muon->Fill(5);
if(  PixSCTHolesForSign && !applyStandaloneIdCut) h_cutflow_mu_muon->Fill(6);
if(  TRTloEtaForSign && !applyStandaloneIdCut) h_cutflow_mu_muon->Fill(7);
if(  TRThiEtaForSign && !applyStandaloneIdCut) h_cutflow_mu_muon->Fill(8);
if(  Z0CutForSign && !applyStandaloneIdCut ) h_cutflow_mu_muon->Fill(9);
if(  D0CutForSign && !applyStandaloneIdCut ) h_cutflow_mu_muon->Fill(10);
if(  PtCutForSign) h_cutflow_mu_muon->Fill(11);
if(  EtaCutForSign) h_cutflow_mu_muon->Fill(12);
if(  SumpT_pTCutForSign) h_cutflow_mu_muon->Fill(13);
if(  SumET_ETCutForSign) h_cutflow_mu_muon->Fill(14);
if(  !OVLMuoRemoveVeto) h_cutflow_mu_muon->Fill(15);
if(  isTight && BLayerForSign && PixelForSign && SCTForSign && PixSCTHolesForSign && TRTloEtaForSign && TRThiEtaForSign && Z0CutForSign && D0CutForSign && PtCutForSign && EtaCutForSign && SumpT_pTCutForSign && SumET_ETCutForSign) h_cutflow_mu_muon->Fill(16);
if(  isTight && BLayerForSign && PixelForSign && SCTForSign && PixSCTHolesForSign && TRTloEtaForSign && TRThiEtaForSign && Z0CutForSign && D0CutForSign && PtCutForSign && EtaCutForSign && SumpT_pTCutForSign && SumET_ETCutForSign  &&  (!OVLMuoRemoveVeto) ) h_cutflow_mu_muon->Fill(17);
else continue;

}

    container t_tmp;
    /////////

    t_tmp.tlv.SetPtEtaPhiM(Pt,Eta,Phi,105.66);
    if(!(*mu_muid_isLowPtReconstructedMuon)[i]) t_tmp.IsLowPt = true;
    t_tmp.pt   = Pt;
    t_tmp.pt_MS   = pT_IDsmeared;
    t_tmp.pt_ID   = pT_MSsmeared;
    t_tmp.eta   = Eta;
    t_tmp.phi   = Phi;
    t_tmp.pt_ori   = Pt_Orignal;
    t_tmp.E   = t_tmp.tlv.E();
    t_tmp.SumPt   = sumpt;
    t_tmp.SumEt   = etconecor30Rel;
    t_tmp.D0      = (*mu_muid_d0_exPV)[i];
    t_tmp.D0sig   = mud0;
    t_tmp.Z0      = (*mu_muid_z0_exPV)[i];
    t_tmp.Z0sig   = muz0;
    t_tmp.NBLayer = (*mu_muid_nBLHits)[i]  ;
    t_tmp.NPixel  = (*mu_muid_nPixHits)[i] ;
    t_tmp.NSCT    = (*mu_muid_nSCTHits)[i] ;
    t_tmp.NTRT    = (*mu_muid_nTRTHits)[i] ;
//    t_tmp.NRPCEta = (*mu_muid_nRPCEtaHits)[i] ;
//    t_tmp.NRPCPhi = (*mu_muid_nRPCPhiHits)[i] ;
    t_tmp.charge       = (*mu_muid_charge)[i];
    t_tmp.pdgID   = t_tmp.charge*13.;
    t_tmp.pxCorr  = muo_delta_px;
    t_tmp.pyCorr  = muo_delta_py;
    t_tmp.index = i;
    t_tmp.pass_looseptcut = PtCutForVeto;
    t_tmp.pass_tightptcut = PtCutForSign;
    t_tmp.pass_tightcut = Pass_tight;
    t_tmp.Et_ms_up = pT_smeared_ms_up; 
    t_tmp.Et_ms_down = pT_smeared_ms_down; 
    t_tmp.Et_id_up = pT_smeared_id_up; 
    t_tmp.Et_id_down = pT_smeared_id_down; 
    t_tmp.EtMS_ms_up = pT_MSsmeared_ms_up; 
    t_tmp.EtMS_ms_down = pT_MSsmeared_ms_down; 
    t_tmp.EtMS_id_up = pT_MSsmeared_id_up; 
    t_tmp.EtMS_id_down = pT_MSsmeared_id_down; 
    t_tmp.EtID_ms_up = pT_IDsmeared_ms_up; 
    t_tmp.EtID_ms_down = pT_IDsmeared_ms_down; 
    t_tmp.EtID_id_up = pT_IDsmeared_id_up; 
    t_tmp.EtID_id_down = pT_IDsmeared_id_down; 
    t_tmp.isCombine = (!applyStandaloneIdCut);
    t_tmp.isStandAlone = applyStandaloneIdCut;
    t_tmp.isCalo = false;
    t_tmp.isTight = mu_muid_tight->at(i);
    t_tmp.isMedium = mu_muid_medium->at(i);
    t_tmp.energy_loss = mu_muid_energyLossPar->at(i);
    t_tmp.not_overlap = (!OVLMuoRemoveVeto);
    t_tmp.theta = mu_muid_theta_exPV->at(i);

   if(!kIsData){

     double _muonSF = m_MCPsf->scaleFactor(t_tmp.charge, t_tmp.tlv); 
     double lepSFStatError = m_MCPsf->scaleFactorUncertainty(t_tmp.charge,t_tmp.tlv); 
     double lepSFSysError = m_MCPsf->scaleFactorSystematicUncertainty(t_tmp.charge,t_tmp.tlv);
     double lepSFError = sqrt(lepSFSysError*lepSFSysError+lepSFStatError*lepSFStatError);
    t_tmp.muon_sf = _muonSF;
    t_tmp.muon_sf_Sta_err = lepSFStatError;
    t_tmp.muon_sf_Sys_err = lepSFSysError;

   }

    muon_index.push_back(t_tmp);
    }
  return muon_index;
}


vector<container> physics::get_calomuon_met(int myRunNumber, int kIsData, TString option, vector<container> jet, vector<container> muon_nocalo ){
  vector<container> muon_index;
  muon_index.clear();

bool get_veto = false; //get veto electrons
bool get_save = false; //get veto electrons
if( option.Contains("veto") )get_veto = true;
if( option.Contains("save") )get_save = true;

  int N_m = mu_calo_n;

  for (Int_t i=0; i < mu_calo_n; i++){

  bool f_tight = true;
  bool f_blayer = true;
  bool f_pix = true;
  bool f_sct = true;
  bool f_holes = true;
  bool f_trt = true;
  bool f_z0 = true;
  bool f_d0 = true;
  bool f_pt = true;
  bool f_eta = true;
  bool f_ptcone = true;
  bool f_or = true;

  bool f_tight_veto = true;
  bool f_blayer_veto = true;
  bool f_pix_veto = true; 
  bool f_sct_veto = true;
  bool f_holes_veto = true;
  bool f_trt_veto = true;
  bool f_z0_veto = true;
  bool f_d0_veto = true;
  bool f_pt_veto = true;
  bool f_eta_veto = true;
  bool f_ptcone_veto = true;
  bool f_or_veto = true;


    Double_t    Pt = (*mu_calo_pt)[i];
    Double_t   Eta = (*mu_calo_eta)[i];
    Double_t   Phi = (*mu_calo_phi)[i];

    Double_t sumpt = (*mu_calo_ptcone20)[i];

    Int_t n_TRT_hit = (*mu_calo_nTRTHits)[i];
    Int_t n_TRT_out = (*mu_calo_nTRTOutliers)[i];
    Int_t n_TRT_tot = n_TRT_hit + n_TRT_out;

    Double_t Charge = (*mu_calo_charge)[i];



    ////////////smearing the MC samples
     double Pt_Orignal = Pt;
     double pT_smeared =Pt;
     double pT_smeared_ms_up =Pt;
     double pT_smeared_ms_down =Pt;
     double pT_smeared_id_up =Pt;
     double pT_smeared_id_down =Pt;
     double pT_IDsmeared =Pt;
     double pT_IDsmeared_ms_up =Pt;
     double pT_IDsmeared_ms_down =Pt;
     double pT_IDsmeared_id_up =Pt;
     double pT_IDsmeared_id_down =Pt;
     double pT_MSsmeared =Pt;
     double pT_MSsmeared_ms_up =Pt;
     double pT_MSsmeared_ms_down =Pt;
     double pT_MSsmeared_id_up =Pt;
     double pT_MSsmeared_id_down =Pt;


/*
    if(!kIsData){
      mcp_smear_muid->SetSeed(EventNumber,i);
      mcp_smear_muid ->Event(Pt_MS, Pt_ID, Pt, Eta, Charge);
        // Get Smeared Pts

      double pt_tmp1(0),pt_tmp2(0);
      pT_smeared = mcp_smear_muid->pTCB();
      pT_IDsmeared = mcp_smear_muid->pTID();
      pT_MSsmeared = mcp_smear_muid->pTMS();

      mcp_smear_muid->PTVar(pT_MSsmeared_id_down,pT_IDsmeared_id_down,pT_smeared_id_down,"IDLOW");
      mcp_smear_muid->PTVar(pT_MSsmeared_id_up,pT_IDsmeared_id_up,pT_smeared_id_up,"IDUP");
      mcp_smear_muid->PTVar(pT_MSsmeared_ms_down,pT_IDsmeared_ms_down,pT_smeared_ms_down,"MSLOW");
      mcp_smear_muid->PTVar(pT_MSsmeared_ms_up,pT_IDsmeared_ms_up,pT_smeared_ms_up,"MSUP");
    }
*/

        bool AuthorForVeto = (( (*mu_calo_author)[i] == 6 ) || ( (*mu_calo_author)[i] ==16 )); 
        bool QualityForVeto = (( (*mu_calo_caloLRLikelihood)[i]>0.9) || ( (*mu_calo_caloMuonIdTag)[i]>10)); 

        bool BLayerForVeto =
            (! mu_calo_expectBLayerHit->at(i)|| mu_calo_nBLHits->at(i)>0);

        bool PixelForVeto = 
           (( mu_calo_nPixHits->at(i) +  mu_calo_nPixelDeadSensors->at(i) )>0);

        // flags for SCT cuts
        bool SCTForVeto = 
           ( (  mu_calo_nSCTHits->at(i) +  mu_calo_nSCTDeadSensors->at(i) )>4);

        // flags for PixSCTHoles cuts
        bool PixSCTHolesForVeto = 
            ( (  mu_calo_nPixHoles->at(i) +  mu_calo_nSCTHoles->at(i) ) < 3);

        // flags for TRT low eta cuts (|eta|<1.9)
        bool TRTloEtaForVeto = (fabs(Eta)>=1.9 || fabs(Eta)<=0.1 ) || 
        (fabs(Eta)<1.9 && fabs(Eta)>0.1 && (n_TRT_tot>5 && (n_TRT_out < 0.9*n_TRT_tot)) );

        // flags for TRT high eta cuts
        bool TRThiEtaForVeto = ( (fabs(Eta)<1.9 && fabs(Eta)>0.1 ) || 
                                (n_TRT_tot<=5 || (n_TRT_out < 0.9*n_TRT_tot)) );


        bool PtCutForVeto = (Pt > 20000);
	bool PtCutForSave = (Pt > 4000);


        bool EtaCutForVeto = (fabs(Eta) <0.1); 


        // flags to check the sumpT/pT cut for both signal and veto.
        bool SumpT_pTCutForVeto = (kIsReverse)?(true):(sumpt/Pt < 0.1 );

        // Compute the calo isolation but correct for NPv pileup effect


    bool OVLMuoRemoveSign = false;
    bool OVLMuoRemoveVeto = false;
    double minDR=0.4;
      if(jet.size() > 0)  {
        for(std::vector<container>::iterator j = jet.begin(); j < jet.end(); j++) {
           double _dphi = caldphi(Phi, j->tlv.Phi());
           double _deta = caldeta(Eta, j->tlv.Eta());
          if(caldr(_dphi, _deta)<minDR) OVLMuoRemoveSign = true;
          if(caldr(_dphi, _deta)<minDR) OVLMuoRemoveVeto = true;
        }
      }

bool Overlap_Calo = false;

   TLorentzVector calo_muon;
   calo_muon.SetPtEtaPhiM(Pt,Eta,Phi,105.66);
   for(unsigned int j=0; j<muon_nocalo.size();j++){
      TLorentzVector noncalo_muon = muon_nocalo.at(j).tlv;
      if (deltaR(calo_muon,noncalo_muon)<0.1) Overlap_Calo=true;
      }   

/*
   for(int nocalo =0;nocalo<mu_muid_n;nocalo++){
    double   Eta_nocalo = (*mu_muid_eta)[nocalo];
    double   Phi_nocalo = (*mu_muid_phi)[nocalo];
    double  _dphi = caldphi(Phi, Phi_nocalo);
    double  _deta = caldeta(Eta, Eta_nocalo);
          if(caldr(_dphi, _deta)<0.4) Overlap_Calo = true;
   } 
*/

////================================after the new update============================================================
bool MCPHitsForVeto = (BLayerForVeto && PixelForVeto && SCTForVeto && PixSCTHolesForVeto && TRTloEtaForVeto && TRThiEtaForVeto);

bool Pass_tight = false;
if(get_save){
if(!PtCutForSave)continue;
//if(!(AuthorForVeto && MCPHitsForVeto && EtaCutForVeto && SumpT_pTCutForVeto && QualityForVeto && (!Overlap_Calo) &&  (!OVLMuoRemoveVeto))) continue;
if(!(AuthorForVeto && MCPHitsForVeto && EtaCutForVeto && QualityForVeto && (!Overlap_Calo) &&  (!OVLMuoRemoveVeto))) continue;//Remove sumpt, for anti-iso
} 


if(get_veto && !get_save){
h_cutflow_mu_muon_2->Fill(1);
if(AuthorForVeto ) h_cutflow_mu_muon_2->Fill(2);
if(BLayerForVeto ) h_cutflow_mu_muon_2->Fill(3);
if(PixelForVeto ) h_cutflow_mu_muon_2->Fill(4);
if(SCTForVeto ) h_cutflow_mu_muon_2->Fill(5);
if(PixSCTHolesForVeto ) h_cutflow_mu_muon_2->Fill(6);
if(TRTloEtaForVeto ) h_cutflow_mu_muon_2->Fill(7);
if(TRThiEtaForVeto ) h_cutflow_mu_muon_2->Fill(8);
if(TRThiEtaForVeto && TRTloEtaForVeto) h_cutflow_mu_muon_2->Fill(9);
if(MCPHitsForVeto) h_cutflow_mu_muon_2->Fill(10);
if(PtCutForVeto ) h_cutflow_mu_muon_2->Fill(11);
if(EtaCutForVeto) h_cutflow_mu_muon_2->Fill(12);
if(SumpT_pTCutForVeto) h_cutflow_mu_muon_2->Fill(13);
if(QualityForVeto) h_cutflow_mu_muon_2->Fill(14);
if(!OVLMuoRemoveVeto) h_cutflow_mu_muon_2->Fill(15);
if(!Overlap_Calo) h_cutflow_mu_muon_2->Fill(16);
if(AuthorForVeto && MCPHitsForVeto && PtCutForVeto && EtaCutForVeto && SumpT_pTCutForVeto && QualityForVeto && (!Overlap_Calo)) h_cutflow_mu_muon_2->Fill(17);
if(AuthorForVeto && MCPHitsForVeto && PtCutForVeto && EtaCutForVeto && SumpT_pTCutForVeto && QualityForVeto && (!Overlap_Calo)) h_cutflow_mu_muon_2->Fill(18);
if(AuthorForVeto && MCPHitsForVeto && PtCutForVeto && EtaCutForVeto && SumpT_pTCutForVeto && QualityForVeto && (!Overlap_Calo)) h_cutflow_mu_muon_1->Fill(26);
if(AuthorForVeto && MCPHitsForVeto && PtCutForVeto && EtaCutForVeto && SumpT_pTCutForVeto && QualityForVeto && (!Overlap_Calo) && (!OVLMuoRemoveVeto) ) h_cutflow_mu_muon_1->Fill(27);
if(AuthorForVeto && MCPHitsForVeto && PtCutForVeto && EtaCutForVeto && SumpT_pTCutForVeto && QualityForVeto && (!Overlap_Calo) &&  (!OVLMuoRemoveVeto) ) h_cutflow_mu_muon_2->Fill(20);
if(AuthorForVeto && MCPHitsForVeto && PtCutForVeto && EtaCutForVeto && SumpT_pTCutForVeto && QualityForVeto && (!Overlap_Calo) &&  (!OVLMuoRemoveVeto) ) h_cutflow_mu_muon_2->Fill(19);
else continue;
}


    container t_tmp;
    /////////

    t_tmp.tlv.SetPtEtaPhiM(Pt,Eta,Phi,105.66);
    t_tmp.IsLowPt = false;
    t_tmp.pt   = Pt;
    t_tmp.pt_MS   = pT_IDsmeared;
    t_tmp.pt_ID   = pT_MSsmeared;
    t_tmp.eta   = Eta;
    t_tmp.phi   = Phi;
    t_tmp.pt_ori   = Pt_Orignal;
    t_tmp.E   = t_tmp.tlv.E();
    t_tmp.SumPt   = sumpt;
    t_tmp.SumEt   = -99;
    t_tmp.D0      = -99;
    t_tmp.D0sig   = -99;
    t_tmp.Z0      = -99;
    t_tmp.Z0sig   = -99;
    t_tmp.NBLayer = (*mu_calo_nBLHits)[i]  ;
    t_tmp.NPixel  = (*mu_calo_nPixHits)[i] ;
    t_tmp.NSCT    = (*mu_calo_nSCTHits)[i] ;
    t_tmp.NTRT    = (*mu_calo_nTRTHits)[i] ;
    t_tmp.charge       = (*mu_calo_charge)[i];
    t_tmp.pdgID   = t_tmp.charge*13.;
    t_tmp.pxCorr  = -99;
    t_tmp.pyCorr  = -99;
    t_tmp.index = i;
    t_tmp.pass_looseptcut = PtCutForVeto;
    t_tmp.pass_tightptcut = false;
    t_tmp.pass_tightcut = false;
    t_tmp.Et_ms_up = pT_smeared_ms_up;
    t_tmp.Et_ms_down = pT_smeared_ms_down;
    t_tmp.Et_id_up = pT_smeared_id_up;
    t_tmp.Et_id_down = pT_smeared_id_down;
    t_tmp.EtMS_ms_up = pT_MSsmeared_ms_up;
    t_tmp.EtMS_ms_down = pT_MSsmeared_ms_down;
    t_tmp.EtMS_id_up = pT_MSsmeared_id_up;
    t_tmp.EtMS_id_down = pT_MSsmeared_id_down;
    t_tmp.EtID_ms_up = pT_IDsmeared_ms_up;
    t_tmp.EtID_ms_down = pT_IDsmeared_ms_down;
    t_tmp.EtID_id_up = pT_IDsmeared_id_up;
    t_tmp.EtID_id_down = pT_IDsmeared_id_down;
    t_tmp.isCombine = false;
    t_tmp.isStandAlone = false;
    t_tmp.isCalo = true;
    t_tmp.isTight = false;
    t_tmp.isMedium = false;


    muon_index.push_back(t_tmp);
    }//saved all the calo muons that are not overlapped with combined muons
    
   for(unsigned int nocalo=0; nocalo<muon_nocalo.size();nocalo++){
   h_cutflow_mu_muon_2->Fill(18);

//Overlap removal with jet 
   bool OVLap = false;
    double minDR=0.4;
      if(jet.size() > 0)  {
        for(std::vector<container>::iterator j = jet.begin(); j < jet.end(); j++) {
           double _dphi = caldphi((muon_nocalo.at(nocalo)).tlv.Phi(), j->tlv.Phi());
           double _deta = caldeta((muon_nocalo.at(nocalo)).tlv.Eta(), j->tlv.Eta());
          if(caldr(_dphi, _deta)<minDR) OVLap = true;
        }
      }
//Overlap removal with jet
   if(OVLap)continue;
   h_cutflow_mu_muon_2->Fill(20);
   muon_index.push_back(muon_nocalo.at(nocalo));
   }//adding all the combined muons    

  return muon_index;
}

vector<container> physics::get_jet_met(int myRunNumber, int kIsData, TString option, vector<container> ele){
vector<container> jet_index;
jet_index.clear();
  Int_t N_j = jet_AntiKt4TopoEM_n;

bool get_veto = false; //get veto electrons
if( option.Contains("veto") )get_veto = true;
bool get_save = false;
if( option.Contains("save") )get_save = true;

  bool PassCleaning=true;



  for (Int_t i=0; i < jet_AntiKt4TopoEM_n; i++){

    Double_t jet_pt    = (*jet_AntiKt4TopoEM_pt)[i];
    Double_t jet_pt_ori    = (*jet_AntiKt4TopoEM_pt)[i];
    Double_t jet_eta   = (*jet_AntiKt4TopoEM_eta)[i];
    Double_t jet_phi   = (*jet_AntiKt4TopoEM_phi)[i];
    Double_t jet_m   = (*jet_AntiKt4TopoEM_m)[i];
    Double_t jet_e     = ((*jet_AntiKt4TopoEM_E)[i]<0) ? 0 : (*jet_AntiKt4TopoEM_E)[i];


    double SmearingFactor(1.0),SmearingFactorSys(1.0),JES_uncert_up(0),JES_uncert_down(0),JES_uncert_NPVup(0),JES_uncert_NPVdown(0),JES_uncert_MUup(0),JES_uncert_MUdown(0);
if(!kIsData){
    //////////////
    //// JER Uncertainty
    ///////////////
my_JetSmearing_NEW->SetSeed(EventNumber);
if(jet_eta>-4.5 && jet_eta<4.5)SmearingFactorSys = my_JetSmearing_NEW->GetRandomSmearingFactorSystRel17(jet_pt,jet_eta); 

    ////////////////
    /// JES Uncertainty
    ////////////////
        Int_t nVtx = 0;

    for (Int_t pv=0;pv<vxp_n;pv++) {
        if( vxp_nTracks->at(pv) >= 3 ) nVtx++;
    }

        double closet_dr = 99;
        for(Int_t jj=0; jj < jet_AntiKt4TopoEM_n; jj++) {
           double t_dphi = caldphi(jet_pt, (*jet_AntiKt4TopoEM_phi)[jj]);
           double t_deta = caldeta(jet_eta, (*jet_AntiKt4TopoEM_phi)[jj]);
           double t_dr = caldr(t_dphi, t_deta);
          if(t_dr<closet_dr && (*jet_AntiKt4TopoEM_pt)[jj]>7000) closet_dr = t_dr;
        }
       bool isBjet =false;
       if(jet_AntiKt4TopoEM_flavor_truth_label->at(i)==5)isBjet=true;

       if( jet_pt > 15000. && jet_pt <7000000. && fabs( jet_eta ) <4.5 ){
        JES_uncert_NPVup = myJES.getRelNPVOffsetTerm( jet_pt, jet_eta, nVtx );
        JES_uncert_NPVdown = myJES.getRelNPVOffsetTerm( jet_pt, jet_eta, nVtx);
        JES_uncert_MUup = myJES.getRelMuOffsetTerm( jet_pt, jet_eta, averageIntPerXing );
        JES_uncert_MUdown = myJES.getRelMuOffsetTerm( jet_pt, jet_eta, averageIntPerXing );

        JES_uncert_up = myJES.getRelUncert( jet_pt, jet_eta, closet_dr, true, nVtx, averageIntPerXing,isBjet);
        JES_uncert_down = myJES.getRelUncert( jet_pt, jet_eta, closet_dr, false, nVtx, averageIntPerXing,isBjet);
      }
}


    // use isBadLoose for rejecting bad jets until the variable
    // isBadLooseMinus will be available (this one is the reccommended)
    bool isBadLoose = (jet_AntiKt4TopoEM_isBadLoose->at(i) == 1 )? true : false;
    bool is_loose   = (isBadLoose)? true : false;
    bool is_ugly    = (jet_AntiKt4TopoEM_isUgly->at(i) == 1)? true : false;

        // Implement the criteria for the Looser bad jet definition, because 
        // the isBadLooseMinus variable is not available inside the p833 SMWZ d3pd
        double jet_chf = (jet_pt!=0.)? jet_AntiKt4TopoEM_sumPtTrk->at(i) / jet_pt : 1;
        bool HECspikes = ( (    jet_AntiKt4TopoEM_hecf->at(i) > 0.5 &&
                           fabs(jet_AntiKt4TopoEM_HECQuality->at(i)) > 0.5 &&
                                jet_AntiKt4TopoEM_AverageLArQF->at(i)/65535. > 0.8 ) ||
                           fabs(jet_AntiKt4TopoEM_NegativeE->at(i))>60000. );
        bool EMCoherentNoise = ( fabs(jet_AntiKt4TopoEM_LArQuality->at(i)) > 0.8 &&
                                      jet_AntiKt4TopoEM_emfrac->at(i) > 0.95 &&
                                      jet_AntiKt4TopoEM_AverageLArQF->at(i)/65535. > 0.8 &&
                                      fabs(jet_eta) < 2.8);
        bool Timing = ( jet_AntiKt4TopoEM_emfrac->at(i) < 0.05 &&
                         jet_chf < 0.05 && fabs(jet_eta) < 2.0 ) ||
                      ( jet_AntiKt4TopoEM_emfrac->at(i) < 0.05 && fabs(jet_eta) >= 2.0)  ||
                      ( jet_AntiKt4TopoEM_fracSamplingMax->at(i) > 0.99 && fabs(jet_eta) < 2.0);

        bool isLooser = (HECspikes || EMCoherentNoise || Timing);

        bool is_bad   = isLooser;

        if(is_bad && (jet_pt > 20000) && (fabs(jet_eta)<4.5)){
         kMETClean = false; 
        }
        // flag stating the jet is good
        bool is_good = (is_bad||is_ugly)? false : true;

        //flags to check the pT cut for both signal and veto
        Int_t PtCutSign = 1;  // == 0. if did not passed the jet pt cut
        Int_t PtCutVeto = 1;  // == 0. if did not passed the jet pt cut veto
        Int_t PtCutSave = 1;  // == 0. if did not passed the jet pt cut veto

        if( jet_pt <= JET_PtCutSign ) PtCutSign  = 0;
        if( jet_pt <= JET_PtCutVeto ) PtCutVeto = 0;
        if( jet_pt <= 15000 ) PtCutSave = 0;


        //flags to check the eta cut for both signal and veto
        Int_t EtaCutSign = 1;  // == 0. if did not passed the jet eta cut
        Int_t EtaCutVeto = 1;  // == 0. if did not passed the jet eta cut veto

        if( fabs(jet_eta) >= JET_EtaCutSign ) EtaCutSign  = 0;
        if( fabs(jet_eta) >= JET_EtaCutVeto ) EtaCutVeto = 0;

        //flags to check the jvf cut for both signal and veto
        Int_t JVFCutSign = 1;  // == 0. if did not passed the jet eta cut
        Int_t JVFCutVeto = 1;  // == 0. if did not passed the jet eta cut veto

        if( fabs(jet_AntiKt4TopoEM_jvtxf->at(i)) <JET_JVFCutSign) JVFCutSign = 0;
        // for Veto apply the JVF cut only on jet having |eta| < 2.5
        //if( (fabs(jet_AntiKt4TopoEM_jvtxf->at(i)) < JET_JVFCutVeto) && fabsf(jet_eta)<2.5 ) JVFCutVeto = 0;
        if( fabs(jet_AntiKt4TopoEM_jvtxf->at(i)) < JET_JVFCutVeto ) JVFCutVeto = 0;

        //flags checking the overlap removal among JET and veto electrons
        bool OVLEleRemoveSign = false; // == true if jet must be removed
        bool OVLEleRemoveVeto = false; // == true if jet must be removed

        for(std::vector<container>::iterator j = ele.begin(); j < ele.end(); j++) {
           double _dphi = caldphi(jet_phi, j->tlv.Phi());
           double _deta = caldeta(jet_eta, j->tlv.Eta());
          if(caldr(_dphi, _deta)<0.4) OVLEleRemoveSign = true;
          if(caldr(_dphi, _deta)<0.4) OVLEleRemoveVeto = true;
        }


//get btag flavour weight
//double btag_MV1 = mv1Eval(jet_AntiKt4TopoEM_flavor_weight_IP3D->at(i), jet_AntiKt4TopoEM_flavor_weight_SV1->at(i),jet_AntiKt4TopoEM_flavor_weight_JetFitterCOMBNN->at(i),jet_pt, jet_eta);
double btag_MV1 = jet_AntiKt4TopoEM_flavor_weight_MV1->at(i);

bool Pass_tight = false;
bool Pass_LowPt = false;
bool Pass_HighPt = false;
bool Pass_SavePt = false;
    ///////////////
if(get_save){
if(jet_e && !isLooser && EtaCutSign && JVFCutSign && !OVLEleRemoveSign)Pass_tight=true;
if(PtCutSign>0)Pass_HighPt=true;
if(PtCutVeto>0)Pass_LowPt=true;
if(PtCutSave>0)Pass_SavePt=true;

if(!Pass_SavePt)continue;
if(!(jet_e && (!is_bad) && PtCutVeto && EtaCutVeto && JVFCutVeto && !OVLEleRemoveVeto) )continue;
if(jet_e && !isLooser && PtCutSign && EtaCutSign && JVFCutSign && !OVLEleRemoveSign)Pass_tight;
}


if(!get_veto && !get_save){
if(jet_e && !isLooser && EtaCutSign && JVFCutSign && !OVLEleRemoveSign)Pass_tight=true;
h_cutflow_jet->Fill(1);
if(jet_e) h_cutflow_jet->Fill(2); 
//if(!isBadLoose) h_cutflow_jet->Fill(3); 
if(!is_bad) h_cutflow_jet->Fill(4); 
//if(!is_ugly) h_cutflow_jet->Fill(5); 
if(PtCutSign) h_cutflow_jet->Fill(6); 
if(EtaCutSign) h_cutflow_jet->Fill(7); 
if(JVFCutSign) h_cutflow_jet->Fill(8); 
if(!OVLEleRemoveSign) h_cutflow_jet->Fill(9); 
if(jet_e && !isLooser && PtCutSign && EtaCutSign && JVFCutSign) h_cutflow_jet->Fill(10);
if(jet_e && !isLooser && PtCutSign && EtaCutSign && JVFCutSign && (btag_MV1>0.795) ) h_cutflow_jet->Fill(11);
if(jet_e && !isLooser && PtCutSign && EtaCutSign && JVFCutSign && !OVLEleRemoveSign && (btag_MV1>0.795) ) h_cutflow_jet->Fill(13);
if(jet_e && !isLooser && PtCutSign && EtaCutSign && JVFCutSign && !OVLEleRemoveSign)h_cutflow_jet->Fill(12);
else continue;

}
   
if(get_veto && !get_save){

h_cutflow_jet_1->Fill(1);
if(jet_e) h_cutflow_jet_1->Fill(2); 
//if(!isBadLoose) h_cutflow_jet_1->Fill(3); 
if(!is_bad) h_cutflow_jet_1->Fill(4);
//if(!is_ugly) h_cutflow_jet_1->Fill(5);
if(PtCutVeto) h_cutflow_jet_1->Fill(6);
if(EtaCutVeto) h_cutflow_jet_1->Fill(7);
if(JVFCutVeto) h_cutflow_jet_1->Fill(8);
if(!OVLEleRemoveVeto) h_cutflow_jet_1->Fill(9);
if(jet_e && (!is_bad) && PtCutVeto && EtaCutVeto && JVFCutVeto) h_cutflow_jet_1->Fill(10);

if(jet_e && (!is_bad) && PtCutVeto && EtaCutVeto && JVFCutVeto && !OVLEleRemoveVeto) h_cutflow_jet_1->Fill(11);

if(jet_e && (!is_bad) && PtCutVeto && EtaCutVeto && JVFCutVeto && !OVLEleRemoveVeto) h_cutflow_jet_1->Fill(12);
else continue;

}


//btagging sf
    TLorentzVector myjet;

    myjet.SetPtEtaPhiM(jet_pt, jet_eta, jet_phi, jet_m);
    Double_t EMJES = (*jet_AntiKt4TopoEM_EMJES)[i];
    Double_t Pt    = jet_pt;
    Double_t Eta   = jet_eta;
    Double_t Phi   = jet_phi;
    Double_t E     = jet_e;
    Double_t M     = jet_m;

    Double_t jet_delta_px = ( Pt - jet_pt ) * cos( Phi );
    Double_t jet_delta_py = ( Pt - jet_pt ) * sin( Phi );
    /////////////////////////////////////////////////////////////
    
float truth_label(0),jet_sf(0),jet_sferr(0),jet_sf_0(0),jet_sferr_0(0),jet_sf_1(0),jet_sferr_1(0),jet_sf_2(0),jet_sferr_2(0),jet_sf_3(0),jet_sferr_3(0),jet_sf_4(0),jet_sferr_4(0);
if(!kIsData){

    if(Pt>200000)ajet.jetPt = 200000; 
    else if(Pt<20000)ajet.jetPt = 20000;
    else ajet.jetPt = Pt;
    ajet.jetEta = Eta;

  string label("Light");
   truth_label = jet_AntiKt4TopoEM_flavor_truth_label->at(i);
   if(truth_label==5)label="B";
   if(truth_label==4)label="C";
   if(truth_label==15)label="T";//truth_label = 15 is Top quark, but we do not have top quark in our config root , so I use it as a light jet
   if(truth_label!=5 && truth_label!=4 && truth_label!=15 )label="Light";//truth_label = 15 is Top quark, but we do not have top quark in our config root , so I use it as a light jet
    Analysis::CalibResult res(1,0); 
    Analysis::CalibResult res_0(1,0); 
    Analysis::CalibResult res_1(1,0); 
    Analysis::CalibResult res_2(1,0); 
    Analysis::CalibResult res_3(1,0); 
    Analysis::CalibResult res_4(1,0); 
    Analysis::CalibResult resineff(1,0);
    Analysis::CalibResult resineff_0(1,0);
    Analysis::CalibResult resineff_1(1,0);
    Analysis::CalibResult resineff_2(1,0);
    Analysis::CalibResult resineff_3(1,0);
    Analysis::CalibResult resineff_4(1,0);

   if(btag_MV1 > 0.795 ){
    // !!! change "B" to "C" or "Light" depending on your true jet flavour, which you need to read from your ntuple branch jet_antiKt4Truth_flavor_truth_trueflav or similar.

    if(truth_label==5){
    res = calib->getScaleFactorEV(ajet, label, "0_795", 0); 

    res_0 = calib->getScaleFactorEV(ajet, label, "0_795", 0); 
    res_1 = calib->getScaleFactorEV(ajet, label, "0_795", 1); 
    res_2 = calib->getScaleFactorEV(ajet, label, "0_795", 2); 
    res_3 = calib->getScaleFactorEV(ajet, label, "0_795", 3); 
    res_4 = calib->getScaleFactorEV(ajet, label, "0_795", 4); 
    }
    else{
    res = calib->getScaleFactor(ajet, label, "0_795", uncertainty); 
	}

    jet_sf=res.first;
    jet_sferr=res.second;
    jet_sf_0=res_0.first;
    jet_sferr_0=res_0.second;
    jet_sf_1=res_1.first;
    jet_sferr_1=res_1.second;
    jet_sf_2=res_2.first;
    jet_sferr_2=res_2.second;
    jet_sf_3=res_3.first;
    jet_sferr_3=res_3.second;
    jet_sf_4=res_4.first;
    jet_sferr_4=res_4.second;
    }
   else {
    // if jet was not tagged, use:
   //////    Uncertainties on inefficiency are anticorrelated to those on efficiency: when you shift one up, shift the other down, and vice versa!
    if(truth_label==5){

     resineff = calib->getInefficiencyScaleFactorEV(ajet, label, "0_795", 0); 

     resineff_0 = calib->getInefficiencyScaleFactorEV(ajet, label, "0_795", 0); 
     resineff_1 = calib->getInefficiencyScaleFactorEV(ajet, label, "0_795", 1); 
     resineff_2 = calib->getInefficiencyScaleFactorEV(ajet, label, "0_795", 2); 
     resineff_3 = calib->getInefficiencyScaleFactorEV(ajet, label, "0_795", 3); 
     resineff_4 = calib->getInefficiencyScaleFactorEV(ajet, label, "0_795", 4); 
   }
   else{
    resineff = calib->getInefficiencyScaleFactorEV(ajet, label, "0_795", uncertainty);
   }
    jet_sf=resineff.first;
    jet_sferr= -1 * resineff.second;
    jet_sf_0=resineff_0.first;
    jet_sferr_0= -1 * resineff_0.second;
    jet_sf_1=resineff_1.first;
    jet_sferr_1=-1 * resineff_1.second;
    jet_sf_2=resineff_2.first;
    jet_sferr_2=-1 * resineff_2.second;
    jet_sf_3=resineff_3.first;
    jet_sferr_3=-1 * resineff_3.second;
    jet_sf_4=resineff_4.first;
    jet_sferr_4=-1 * resineff_4.second;

   } 

}
//finish btagging sf

   ////////////////////////////////////////////////////////
    container t_tmp;
//cout<<"Event number "<< EventNumber <<"   "<< jet_pt <<"  "<<jet_eta<<"   "<<jet_phi<<"  "<<jet_m<<endl;
    t_tmp.tlv.SetPtEtaPhiM(jet_pt,jet_eta,jet_phi,jet_m);
    t_tmp.pdgID   = 0.;
    t_tmp.pxCorr  = jet_delta_px;
    t_tmp.pyCorr  = jet_delta_py;
    t_tmp.pt = jet_pt;
    t_tmp.pt_ori = jet_pt_ori;
    t_tmp.eta = jet_eta;
    t_tmp.phi = jet_phi;
    t_tmp.E = jet_e;
    t_tmp.truth_label = truth_label;

    //t_tmp.jetProb     = (*jet_AntiKt4TopoEM_flavor_weight_JetProb)[i];
    t_tmp.jetProb     = 0; 
    t_tmp.jetSV0      = (*jet_AntiKt4TopoEM_flavor_weight_SV0)[i];
    //t_tmp.jetIP3D_SV1 = (*jet_AntiKt4TopoEM_flavor_weight_Comb)[i];
    t_tmp.jetIP3D_SV1 = btag_MV1; 
    t_tmp.jetFitter = btag_MV1;
    t_tmp.jet_jvf     = (*jet_AntiKt4TopoEM_jvtxf)[i]; // this is temporarily used
    t_tmp.index = i;
    t_tmp.jet_Bsf = jet_sf;
    t_tmp.jet_Bsferr = jet_sferr;
    t_tmp.jet_Bsf_0 = jet_sf_0;
    t_tmp.jet_Bsferr_0 = jet_sferr_0;
    t_tmp.jet_Bsf_1 = jet_sf_1;
    t_tmp.jet_Bsferr_1 = jet_sferr_1;
    t_tmp.jet_Bsf_2 = jet_sf_2;
    t_tmp.jet_Bsferr_2 = jet_sferr_2;
    t_tmp.jet_Bsf_3 = jet_sf_3;
    t_tmp.jet_Bsferr_3 = jet_sferr_3;
    t_tmp.jet_Bsf_4 = jet_sf_4;
    t_tmp.jet_Bsferr_4 = jet_sferr_4;

    t_tmp.JER_smear = SmearingFactor;
    t_tmp.JER_smear_sys = SmearingFactorSys;
    t_tmp.JES_uncert_up = JES_uncert_up; 
    t_tmp.JES_uncert_down = JES_uncert_down; 
    t_tmp.JES_uncert_npv = JES_uncert_NPVdown; 
    t_tmp.JES_uncert_mu = JES_uncert_MUdown; 
    t_tmp.pass_looseptcut = Pass_LowPt; 
    t_tmp.pass_tightptcut =  Pass_HighPt;
    t_tmp.pass_tightcut =  Pass_tight;


    t_tmp.jetbad = isLooser;
    jet_index.push_back(t_tmp);
    }

return jet_index;
}

bool physics::bookBranch(){
m_tree = new TTree("physics","physics");

h_jet_n = 0;
h_jet_E= new std::vector<float>();
h_jet_pt= new std::vector<float>();
h_jet_pt_ori= new std::vector<float>();
h_jet_eta= new std::vector<float>();
h_jet_phi= new std::vector<float>();
h_jet_weight= new std::vector<float>();
h_jet_jvf= new std::vector<float>();
h_jet_bad= new std::vector<float>();
h_jet_Btagsf= new std::vector<float>();
h_jet_Btagsferr= new std::vector<float>();
h_jet_Btagsf_0= new std::vector<float>();
h_jet_Btagsferr_0= new std::vector<float>();
h_jet_Btagsf_1= new std::vector<float>();
h_jet_Btagsferr_1= new std::vector<float>();
h_jet_Btagsf_2= new std::vector<float>();
h_jet_Btagsferr_2= new std::vector<float>();
h_jet_Btagsf_3= new std::vector<float>();
h_jet_Btagsferr_3= new std::vector<float>();
h_jet_Btagsf_4= new std::vector<float>();
h_jet_Btagsferr_4= new std::vector<float>();

h_jet_ResFactor= new std::vector<float>();
h_jet_ResFactorSys= new std::vector<float>();
h_jet_ScaleUncertUp= new std::vector<float>();
h_jet_ScaleUncertDo= new std::vector<float>();
h_jet_ScaleUncertNPV= new std::vector<float>();
h_jet_ScaleUncertMU= new std::vector<float>();
h_jet_Pass_LowPt= new std::vector<bool>();
h_jet_Pass_HighPt= new std::vector<bool>();
h_jet_Pass_TightCut= new std::vector<bool>();
h_jet_label= new std::vector<int>();

h_elec_n=0;
h_elec_E = new std::vector<float>();
h_elec_pt = new std::vector<float>();
h_elec_pt_ori = new std::vector<float>();
h_elec_pt_up = new std::vector<float>();
h_elec_pt_down = new std::vector<float>();
h_elec_pt_Rup = new std::vector<float>();
h_elec_pt_Rdown = new std::vector<float>();
h_elec_eta = new std::vector<float>();
h_elec_phi = new std::vector<float>();
h_elec_sumpt = new std::vector<float>();
h_elec_sumet = new std::vector<float>();
h_elec_charge = new std::vector<float>();
h_elec_mt = new std::vector<float>();
h_elec_sf = new std::vector<float>();
h_elec_sf_err = new std::vector<float>();
h_elec_recsf = new std::vector<float>();
h_elec_recsf_err = new std::vector<float>();
h_elec_trig_e20 = new std::vector<float>();
h_elec_trig_e22 = new std::vector<float>();
h_elec_trig_e22vh = new std::vector<float>();
h_elec_Pass_LowPt = new std::vector<bool>();
h_elec_Pass_HighPt = new std::vector<bool>();
h_elec_Pass_TightCut = new std::vector<bool>();
h_elec_tight = new std::vector<bool>();
h_elec_medium = new std::vector<bool>();


h_muon_n=0;
h_muon_E = new std::vector<float>();
h_muon_pt = new std::vector<float>();
h_muon_pt_id = new std::vector<float>();
h_muon_pt_ms = new std::vector<float>();
h_muon_pt_ori = new std::vector<float>();
h_muon_pt_ms_up = new std::vector<float>();
h_muon_pt_ms_down = new std::vector<float>();
h_muon_pt_id_up = new std::vector<float>();
h_muon_pt_id_down = new std::vector<float>();
h_muon_pt_MS_ms_up = new std::vector<float>();
h_muon_pt_MS_ms_down = new std::vector<float>();
h_muon_pt_MS_id_up = new std::vector<float>();
h_muon_pt_MS_id_down = new std::vector<float>();
h_muon_pt_ID_ms_up = new std::vector<float>();
h_muon_pt_ID_ms_down = new std::vector<float>();
h_muon_pt_ID_id_up = new std::vector<float>();
h_muon_pt_ID_id_down = new std::vector<float>();
h_muon_eta = new std::vector<float>();
h_muon_phi = new std::vector<float>();
h_muon_sumet = new std::vector<float>();
h_muon_sumpt = new std::vector<float>();
h_muon_charge = new std::vector<float>();
h_muon_theta = new std::vector<float>();
h_muon_theta = new std::vector<float>();
h_muon_mt = new std::vector<float>();
h_muon_sf = new std::vector<float>();
h_muon_sf_Sta_err = new std::vector<float>();
h_muon_sf_Sys_err = new std::vector<float>();
h_muon_energyloss = new std::vector<float>();
h_muon_not_overlap = new std::vector<bool>();
h_muon_Pass_LowPt = new std::vector<bool>();
h_muon_Pass_HighPt = new std::vector<bool>();
h_muon_Pass_TightCut = new std::vector<bool>();
h_muon_isCombine = new std::vector<bool>();
h_muon_isStandAlone = new std::vector<bool>();
h_muon_isCalo = new std::vector<bool>();
h_muon_tight = new std::vector<bool>();
h_muon_medium = new std::vector<bool>();

h_muon_trigsf=0;
h_muon_trigsfsys=0;

h_RunNumber=0;
h_EventNumber=0;
h_lbn=0;
h_mu=0;

h_EF_mu18_MG=0;
h_EF_e20_medium=0;
h_EF_xe80T_tclcw_loose=0;
h_EF_xe80_tclcw_loose=0;

h_met=0;
h_met_box=0;
h_met_CellOutUp=0;
h_met_CellOutDo=0;
h_met_SoftJetUp=0;
h_met_SoftJetDo=0;
h_met_SoftJetResoUp=0;
h_met_SoftJetResoDo=0;
h_stvf_SoftJetUp=0;
h_stvf_SoftJetDo=0;
h_stvf_SoftJetResoUp=0;
h_stvf_SoftJetResoDo=0;


h_metx=0;
h_mety=0;
h_metphi=0;
h_mt=0;
h_pt=0;
h_mll=0;

h_HforRej=0;
h_weight=0;
h_weight_1=0;
h_weight_2=0;
h_weight_3=0;
h_weight_4=0;
h_Pweight=0;
h_jetclean=0;
h_metclean=0;
h_NGoodVtx=0;
h_pass_lepton_veto=0;
h_pass_jet_veto=0;
h_pass_grl=0;

h_njet=0;
h_nbjet=0;
h_nhjet=0;
h_jjdr=0;

m_tree->Branch("jet_n",&h_jet_n );
m_tree->Branch("jet_E",&h_jet_E );
m_tree->Branch("jet_pt",&h_jet_pt );
m_tree->Branch("jet_pt_ori",&h_jet_pt_ori );
m_tree->Branch("jet_eta",&h_jet_eta );
m_tree->Branch("jet_phi",&h_jet_phi );
m_tree->Branch("jet_weight",&h_jet_weight );
m_tree->Branch("jet_jvf",&h_jet_jvf );
m_tree->Branch("jet_bad",&h_jet_bad );
m_tree->Branch("jet_Btagsf",&h_jet_Btagsf );
m_tree->Branch("jet_Btagsferr",&h_jet_Btagsferr );
m_tree->Branch("jet_Btagsf_0",&h_jet_Btagsf_0 );
m_tree->Branch("jet_Btagsferr_0",&h_jet_Btagsferr_0 );
m_tree->Branch("jet_Btagsf_1",&h_jet_Btagsf_1 );
m_tree->Branch("jet_Btagsferr_1",&h_jet_Btagsferr_1 );
m_tree->Branch("jet_Btagsf_2",&h_jet_Btagsf_2 );
m_tree->Branch("jet_Btagsferr_2",&h_jet_Btagsferr_2 );
m_tree->Branch("jet_Btagsf_3",&h_jet_Btagsf_3 );
m_tree->Branch("jet_Btagsferr_3",&h_jet_Btagsferr_3 );
m_tree->Branch("jet_Btagsf_4",&h_jet_Btagsf_4 );
m_tree->Branch("jet_Btagsferr_4",&h_jet_Btagsferr_4 );
m_tree->Branch("jet_ResFactor",&h_jet_ResFactor );
m_tree->Branch("jet_ResFactorSys",&h_jet_ResFactorSys );
m_tree->Branch("jet_ScaleUncertUp",&h_jet_ScaleUncertUp );
m_tree->Branch("jet_ScaleUncertDo",&h_jet_ScaleUncertDo );
m_tree->Branch("jet_ScaleUncertNPV",&h_jet_ScaleUncertNPV);
m_tree->Branch("jet_ScaleUncertMU",&h_jet_ScaleUncertMU);
m_tree->Branch("jet_Pass_LowPt",&h_jet_Pass_LowPt );
m_tree->Branch("jet_Pass_HighPt",&h_jet_Pass_HighPt );
m_tree->Branch("jet_Pass_TightCut",&h_jet_Pass_TightCut );
m_tree->Branch("jet_label",&h_jet_label );

m_tree->Branch("elec_n",&h_elec_n );
m_tree->Branch("elec_E",&h_elec_E );
m_tree->Branch("elec_pt",&h_elec_pt );
m_tree->Branch("elec_pt_ori",&h_elec_pt_ori);
m_tree->Branch("elec_pt_up",&h_elec_pt_up );
m_tree->Branch("elec_pt_down",&h_elec_pt_down );
m_tree->Branch("elec_pt_Rup",&h_elec_pt_Rup );
m_tree->Branch("elec_pt_Rdown",&h_elec_pt_Rdown );
m_tree->Branch("elec_eta",&h_elec_eta );
m_tree->Branch("elec_phi",&h_elec_phi );
m_tree->Branch("elec_sumpt",&h_elec_sumpt );
m_tree->Branch("elec_sumet",&h_elec_sumet );
m_tree->Branch("elec_charge",&h_elec_charge );
m_tree->Branch("elec_mt",&h_elec_mt );
m_tree->Branch("elec_sf",&h_elec_sf );
m_tree->Branch("elec_sf_err",&h_elec_sf_err );
m_tree->Branch("elec_recsf",&h_elec_recsf );
m_tree->Branch("elec_recsf_err",&h_elec_recsf_err );
m_tree->Branch("elec_trig_e20",&h_elec_trig_e20 );
m_tree->Branch("elec_trig_e22",&h_elec_trig_e22 );
m_tree->Branch("elec_trig_e22vh",&h_elec_trig_e22vh );
m_tree->Branch("elec_Pass_LowPt",&h_elec_Pass_LowPt );
m_tree->Branch("elec_Pass_HighPt",&h_elec_Pass_HighPt );
m_tree->Branch("elec_Pass_TightCut",&h_elec_Pass_TightCut );
m_tree->Branch("elec_tight",&h_elec_tight );
m_tree->Branch("elec_medium",&h_elec_medium );

m_tree->Branch("muon_n",&h_muon_n );
m_tree->Branch("muon_E",&h_muon_E );
m_tree->Branch("muon_pt",&h_muon_pt );
m_tree->Branch("muon_pt_ms",&h_muon_pt_ms );
m_tree->Branch("muon_pt_id",&h_muon_pt_id );
m_tree->Branch("muon_pt_ori",&h_muon_pt_ori );
m_tree->Branch("muon_pt_ms_down",&h_muon_pt_ms_down );
m_tree->Branch("muon_pt_id_down",&h_muon_pt_id_down );
m_tree->Branch("muon_pt_ms_up",&h_muon_pt_ms_up );
m_tree->Branch("muon_pt_id_up",&h_muon_pt_id_up );
m_tree->Branch("muon_pt_MS_ms_down",&h_muon_pt_MS_ms_down );
m_tree->Branch("muon_pt_MS_id_down",&h_muon_pt_MS_id_down );
m_tree->Branch("muon_pt_MS_ms_up",&h_muon_pt_MS_ms_up );
m_tree->Branch("muon_pt_MS_id_up",&h_muon_pt_MS_id_up );
m_tree->Branch("muon_pt_ID_ms_down",&h_muon_pt_ID_ms_down );
m_tree->Branch("muon_pt_ID_id_down",&h_muon_pt_ID_id_down );
m_tree->Branch("muon_pt_ID_ms_up",&h_muon_pt_ID_ms_up );
m_tree->Branch("muon_pt_ID_id_up",&h_muon_pt_ID_id_up );
m_tree->Branch("muon_eta",&h_muon_eta );
m_tree->Branch("muon_phi",&h_muon_phi );
m_tree->Branch("muon_sumet",&h_muon_sumet );
m_tree->Branch("muon_sumpt",&h_muon_sumpt );
m_tree->Branch("muon_charge",&h_muon_charge );
m_tree->Branch("muon_theta",&h_muon_theta );
m_tree->Branch("muon_mt",&h_muon_mt );
m_tree->Branch("muon_sf",&h_muon_sf );
m_tree->Branch("muon_sf_Sta_err",&h_muon_sf_Sta_err );
m_tree->Branch("muon_sf_Sys_err",&h_muon_sf_Sys_err );
m_tree->Branch("muon_energyloss",&h_muon_energyloss );
m_tree->Branch("muon_not_overlap",&h_muon_not_overlap );
m_tree->Branch("muon_Pass_LowPt",&h_muon_Pass_LowPt );
m_tree->Branch("muon_Pass_HighPt",&h_muon_Pass_HighPt );
m_tree->Branch("muon_Pass_TightCut",&h_muon_Pass_TightCut );
m_tree->Branch("muon_isCombine",&h_muon_isCombine );
m_tree->Branch("muon_isStandAlone",&h_muon_isStandAlone );
m_tree->Branch("muon_isCalo",&h_muon_isCalo );
m_tree->Branch("muon_tight",&h_muon_tight );
m_tree->Branch("muon_medium",&h_muon_medium );
m_tree->Branch("muon_trigsf",&h_muon_trigsf );
m_tree->Branch("muon_trigsfsys",&h_muon_trigsfsys);


m_tree->Branch("RunNumber",&h_RunNumber );
m_tree->Branch("EventNumber",&h_EventNumber );
m_tree->Branch("lbn",&h_lbn );
m_tree->Branch("mu",&h_mu );

m_tree->Branch("EF_mu18_MG",&h_EF_mu18_MG );
m_tree->Branch("EF_e20_medium",&h_EF_e20_medium );
m_tree->Branch("EF_xe80T_tclcw_loose",&h_EF_xe80T_tclcw_loose );
m_tree->Branch("EF_xe80_tclcw_loose",&h_EF_xe80_tclcw_loose );
m_tree->Branch("met",&h_met );
m_tree->Branch("met_box",&h_met_box );
m_tree->Branch("met_CellOutUp",&h_met_CellOutUp );
m_tree->Branch("met_CellOutDo",&h_met_CellOutDo );
m_tree->Branch("met_SoftJetUp",&h_met_SoftJetUp );
m_tree->Branch("met_SoftJetDo",&h_met_SoftJetDo );
m_tree->Branch("met_SoftJetResoUp",&h_met_SoftJetResoUp );
m_tree->Branch("met_SoftJetResoDo",&h_met_SoftJetResoDo );
m_tree->Branch("stvf_SoftJetUp",&h_stvf_SoftJetUp );
m_tree->Branch("stvf_SoftJetDo",&h_stvf_SoftJetDo );
m_tree->Branch("stvf_SoftJetResoUp",&h_stvf_SoftJetResoUp );
m_tree->Branch("stvf_SoftJetResoDo",&h_stvf_SoftJetResoDo );
m_tree->Branch("metx",&h_metx );
m_tree->Branch("mety",&h_mety );
m_tree->Branch("metphi",&h_metphi );
m_tree->Branch("mt",&h_mt );
m_tree->Branch("pt",&h_pt );
m_tree->Branch("mll",&h_mll);

m_tree->Branch("refinal_met",&h_refinal_met );
m_tree->Branch("refinal_metphi",&h_refinal_metphi );
m_tree->Branch("refinal_sumet",&h_refinal_sumet );
m_tree->Branch("refinal_metphi_C",&h_refinal_metphi_C );
m_tree->Branch("refinal_sumet_C",&h_refinal_sumet_C );
m_tree->Branch("refinal_etx_C",&h_refinal_etx_C );
m_tree->Branch("refinal_ety_C",&h_refinal_ety_C );
m_tree->Branch("refinal_metphi_E",&h_refinal_metphi_E );
m_tree->Branch("refinal_sumet_E",&h_refinal_sumet_E );
m_tree->Branch("refinal_etx_E",&h_refinal_etx_E );
m_tree->Branch("refinal_ety_E",&h_refinal_ety_E );
m_tree->Branch("refinal_metphi_F",&h_refinal_metphi_F );
m_tree->Branch("refinal_sumet_F",&h_refinal_sumet_F );
m_tree->Branch("refinal_etx_F",&h_refinal_etx_F );
m_tree->Branch("refinal_ety_F",&h_refinal_ety_F );

m_tree->Branch("track_met",&h_track_met );
m_tree->Branch("track_metphi",&h_track_metphi );
m_tree->Branch("track_sumet",&h_track_sumet );
m_tree->Branch("track_metphi_C",&h_track_metphi_C );
m_tree->Branch("track_sumet_C",&h_track_sumet_C );
m_tree->Branch("track_etx_C",&h_track_etx_C );
m_tree->Branch("track_ety_C",&h_track_ety_C );
m_tree->Branch("track_metphi_E",&h_track_metphi_E );
m_tree->Branch("track_sumet_E",&h_track_sumet_E );
m_tree->Branch("track_etx_E",&h_track_etx_E );
m_tree->Branch("track_ety_E",&h_track_ety_E );
m_tree->Branch("track_metphi_F",&h_track_metphi_F );
m_tree->Branch("track_sumet_F",&h_track_sumet_F );
m_tree->Branch("track_etx_F",&h_track_etx_F );
m_tree->Branch("track_ety_F",&h_track_ety_F );

m_tree->Branch("refinal_stvf_met",&h_refinal_stvf_met );
m_tree->Branch("refinal_stvf_metphi",&h_refinal_stvf_metphi );
m_tree->Branch("refinal_stvf_sumet",&h_refinal_stvf_sumet );
m_tree->Branch("refinal_stvf_etx",&h_refinal_stvf_etx );
m_tree->Branch("refinal_stvf_ety",&h_refinal_stvf_ety );
m_tree->Branch("refinal_stvf_metphi_C",&h_refinal_stvf_metphi_C );
m_tree->Branch("refinal_stvf_sumet_C",&h_refinal_stvf_sumet_C );
m_tree->Branch("refinal_stvf_etx_C",&h_refinal_stvf_etx_C );
m_tree->Branch("refinal_stvf_ety_C",&h_refinal_stvf_ety_C );
m_tree->Branch("refinal_stvf_metphi_E",&h_refinal_stvf_metphi_E );
m_tree->Branch("refinal_stvf_sumet_E",&h_refinal_stvf_sumet_E );
m_tree->Branch("refinal_stvf_etx_E",&h_refinal_stvf_etx_E );
m_tree->Branch("refinal_stvf_ety_E",&h_refinal_stvf_ety_E );
m_tree->Branch("refinal_stvf_metphi_F",&h_refinal_stvf_metphi_F );
m_tree->Branch("refinal_stvf_sumet_F",&h_refinal_stvf_sumet_F );
m_tree->Branch("refinal_stvf_etx_F",&h_refinal_stvf_etx_F );
m_tree->Branch("refinal_stvf_ety_F",&h_refinal_stvf_ety_F );

m_tree->Branch("softjets_met",&h_softjets_met );
m_tree->Branch("softjets_metphi",&h_softjets_metphi );
m_tree->Branch("softjets_sumet",&h_softjets_sumet );
m_tree->Branch("softjets_metphi_C",&h_softjets_metphi_C );
m_tree->Branch("softjets_sumet_C",&h_softjets_sumet_C );
m_tree->Branch("softjets_etx_C",&h_softjets_etx_C );
m_tree->Branch("softjets_ety_C",&h_softjets_ety_C );
m_tree->Branch("softjets_metphi_E",&h_softjets_metphi_E );
m_tree->Branch("softjets_sumet_E",&h_softjets_sumet_E );
m_tree->Branch("softjets_etx_E",&h_softjets_etx_E );
m_tree->Branch("softjets_ety_E",&h_softjets_ety_E );
m_tree->Branch("softjets_metphi_F",&h_softjets_metphi_F );
m_tree->Branch("softjets_sumet_F",&h_softjets_sumet_F );
m_tree->Branch("softjets_etx_F",&h_softjets_etx_F );
m_tree->Branch("softjets_ety_F",&h_softjets_ety_F );

m_tree->Branch("truth_etx",&h_truth_etx);
m_tree->Branch("truth_ety",&h_truth_ety);
m_tree->Branch("truth_phi", &h_truth_phi);
m_tree->Branch("truth_et",&h_truth_et);
m_tree->Branch("truth_sumet",&h_truth_sumet);

m_tree->Branch("refjet_met",&h_refjet_met );
m_tree->Branch("refjet_metphi",&h_refjet_metphi );
m_tree->Branch("refjet_sumet",&h_refjet_sumet );
m_tree->Branch("refjet_metphi_C",&h_refjet_metphi_C );
m_tree->Branch("refjet_sumet_C",&h_refjet_sumet_C );
m_tree->Branch("refjet_etx_C",&h_refjet_etx_C );
m_tree->Branch("refjet_ety_C",&h_refjet_ety_C );
m_tree->Branch("refjet_metphi_E",&h_refjet_metphi_E );
m_tree->Branch("refjet_sumet_E",&h_refjet_sumet_E );
m_tree->Branch("refjet_etx_E",&h_refjet_etx_E );
m_tree->Branch("refjet_ety_E",&h_refjet_ety_E );
m_tree->Branch("refjet_metphi_F",&h_refjet_metphi_F );
m_tree->Branch("refjet_sumet_F",&h_refjet_sumet_F );
m_tree->Branch("refjet_etx_F",&h_refjet_etx_F );
m_tree->Branch("refjet_ety_F",&h_refjet_ety_F );

m_tree->Branch("cellout_eflow_met",&h_cellout_eflow_met );
m_tree->Branch("cellout_eflow_metphi",&h_cellout_eflow_metphi );
m_tree->Branch("cellout_eflow_sumet",&h_cellout_eflow_sumet );
m_tree->Branch("cellout_eflow_metphi_C",&h_cellout_eflow_metphi_C );
m_tree->Branch("cellout_eflow_sumet_C",&h_cellout_eflow_sumet_C );
m_tree->Branch("cellout_eflow_etx_C",&h_cellout_eflow_etx_C );
m_tree->Branch("cellout_eflow_ety_C",&h_cellout_eflow_ety_C );
m_tree->Branch("cellout_eflow_metphi_E",&h_cellout_eflow_metphi_E );
m_tree->Branch("cellout_eflow_sumet_E",&h_cellout_eflow_sumet_E );
m_tree->Branch("cellout_eflow_etx_E",&h_cellout_eflow_etx_E );
m_tree->Branch("cellout_eflow_ety_E",&h_cellout_eflow_ety_E );
m_tree->Branch("cellout_eflow_metphi_F",&h_cellout_eflow_metphi_F );
m_tree->Branch("cellout_eflow_sumet_F",&h_cellout_eflow_sumet_F );
m_tree->Branch("cellout_eflow_etx_F",&h_cellout_eflow_etx_F );
m_tree->Branch("cellout_eflow_ety_F",&h_cellout_eflow_ety_F );






m_tree->Branch("HforRej",&h_HforRej );
m_tree->Branch("weight",&h_weight );
m_tree->Branch("weight_1",&h_weight_1 );
m_tree->Branch("weight_2",&h_weight_2 );
m_tree->Branch("weight_3",&h_weight_3 );
m_tree->Branch("weight_4",&h_weight_4 );
m_tree->Branch("Pweight",&h_Pweight );
m_tree->Branch("jetclean",&h_jetclean );
m_tree->Branch("metclean",&h_metclean );
m_tree->Branch("NGoodVtx",&h_NGoodVtx );
m_tree->Branch("pass_lepton_veto",&h_pass_lepton_veto );
m_tree->Branch("pass_jet_veto",&h_pass_jet_veto );
m_tree->Branch("pass_grl",&h_pass_grl );


m_tree->Branch("njet",&h_njet );
m_tree->Branch("nbjet",&h_nbjet );
m_tree->Branch("nhjet",&h_nhjet );
m_tree->Branch("jjdr",&h_jjdr );

return kTRUE;
}

bool physics::clearBranch()
{
h_jet_n=0;
h_jet_E->clear();
h_jet_pt->clear();
h_jet_pt_ori->clear();
h_jet_eta->clear();
h_jet_phi->clear();
h_jet_weight->clear();
h_jet_jvf->clear();
h_jet_bad->clear();
h_jet_Btagsf->clear();
h_jet_Btagsferr->clear();
h_jet_Btagsf_0->clear();
h_jet_Btagsferr_0->clear();
h_jet_Btagsf_1->clear();
h_jet_Btagsferr_1->clear();
h_jet_Btagsf_2->clear();
h_jet_Btagsferr_2->clear();
h_jet_Btagsf_3->clear();
h_jet_Btagsferr_3->clear();
h_jet_Btagsf_4->clear();
h_jet_Btagsferr_4->clear();
h_jet_ResFactor->clear();
h_jet_ResFactorSys->clear();
h_jet_ScaleUncertUp->clear();
h_jet_ScaleUncertDo->clear();
h_jet_ScaleUncertNPV->clear();
h_jet_ScaleUncertMU->clear();
h_jet_Pass_LowPt->clear();
h_jet_Pass_HighPt->clear();
h_jet_Pass_TightCut->clear();
h_jet_ResFactor->clear();
h_jet_ResFactorSys->clear();
h_jet_Pass_LowPt->clear();
h_jet_Pass_HighPt->clear();
h_jet_Pass_TightCut->clear();
h_jet_label->clear();


h_elec_n=0;
h_elec_E->clear();
h_elec_pt->clear();
h_elec_pt_ori->clear();
h_elec_pt_up->clear();
h_elec_pt_down->clear();
h_elec_pt_Rup->clear();
h_elec_pt_Rdown->clear();
h_elec_eta->clear();
h_elec_phi->clear();
h_elec_sumet->clear();
h_elec_sumpt->clear();
h_elec_charge->clear();
h_elec_mt->clear();
h_elec_sf->clear();
h_elec_sf_err->clear();
h_elec_recsf->clear();
h_elec_recsf_err->clear();
h_elec_trig_e20->clear();
h_elec_trig_e22->clear();
h_elec_trig_e22vh->clear();
h_elec_Pass_LowPt->clear();
h_elec_Pass_HighPt->clear();
h_elec_Pass_TightCut->clear();
h_elec_tight->clear();
h_elec_medium->clear();


h_muon_n=0;
h_muon_E->clear();
h_muon_pt->clear();
h_muon_pt_ms->clear();
h_muon_pt_id->clear();
h_muon_pt_ori->clear();
h_muon_pt_ms_up->clear();
h_muon_pt_ms_down->clear();
h_muon_pt_id_up->clear();
h_muon_pt_id_down->clear();
h_muon_pt_MS_ms_up->clear();
h_muon_pt_MS_ms_down->clear();
h_muon_pt_MS_id_up->clear();
h_muon_pt_MS_id_down->clear();
h_muon_pt_ID_ms_up->clear();
h_muon_pt_ID_ms_down->clear();
h_muon_pt_ID_id_up->clear();
h_muon_pt_ID_id_down->clear();
h_muon_eta->clear();
h_muon_phi->clear();
h_muon_sumet->clear();
h_muon_sumpt->clear();
h_muon_charge->clear();
h_muon_theta->clear();
h_muon_mt->clear();
h_muon_sf->clear();
h_muon_sf_Sta_err->clear();
h_muon_sf_Sys_err->clear();
h_muon_energyloss->clear();
h_muon_not_overlap->clear();
h_muon_Pass_LowPt->clear();
h_muon_Pass_HighPt->clear();
h_muon_Pass_TightCut->clear();
h_muon_isCombine->clear();
h_muon_isStandAlone->clear();
h_muon_isCalo->clear();
h_muon_tight->clear();
h_muon_medium->clear();

h_muon_trigsf=0;
h_muon_trigsfsys=0;

h_RunNumber=0;
h_EventNumber=0;
h_lbn=0;
h_mu=0;

h_EF_mu18_MG=0;
h_EF_e20_medium=0;
h_EF_xe80T_tclcw_loose=0;
h_EF_xe80_tclcw_loose=0;
h_met=0;
h_met_box=0;
h_metx=0;
h_mety=0;
h_metphi=0;
h_mt=0;

h_HforRej=0;
h_weight=0;
h_weight_1=0;
h_weight_2=0;
h_weight_3=0;
h_weight_4=0;
h_Pweight=0;
h_jetclean=0;
h_metclean=0;
h_NGoodVtx=0;
h_pass_lepton_veto=0;
h_pass_jet_veto=0;
h_pass_grl=0;

h_njet =0;
h_nbjet =0;
h_nhjet =0;
h_jjdr =0;

return kTRUE;
}


void physics::Set_Branch(Long64_t entry)
{

  TString option = GetOption();

  bool DoOwnBranch = true;
    //bool DoOwnBranch = false;
  if(!DoOwnBranch) {
    GetEntry(entry);
  }else{
   b_RunNumber->GetEntry(entry);   //!
   b_EventNumber->GetEntry(entry);   //!
   b_averageIntPerXing->GetEntry(entry);   //!
   b_lbn->GetEntry(entry);   //!
   b_larError->GetEntry(entry);   //!
   b_el_n->GetEntry(entry);   //!
   b_el_E->GetEntry(entry);   //!
   b_el_Et->GetEntry(entry);   //!
   b_el_pt->GetEntry(entry);   //!
   b_el_m->GetEntry(entry);   //!
   b_el_eta->GetEntry(entry);   //!
   b_el_CaloPointing_eta->GetEntry(entry);   //!
   b_el_phi->GetEntry(entry);   //!
   b_el_px->GetEntry(entry);   //!
   b_el_py->GetEntry(entry);   //!
   b_el_pz->GetEntry(entry);   //!
   b_el_charge->GetEntry(entry);   //!
   b_el_author->GetEntry(entry);   //!
   b_el_isEM->GetEntry(entry);   //!
   b_el_OQ->GetEntry(entry);   //!
//add for isem tight
    b_el_Ethad->GetEntry(entry);
    b_el_Ethad1->GetEntry(entry);
    b_el_wstot->GetEntry(entry);
    b_el_deltaEs->GetEntry(entry);
    b_el_Emax2->GetEntry(entry);
    b_el_emaxs1->GetEntry(entry);
    b_el_deltaeta1->GetEntry(entry);
    b_el_deltaphi2->GetEntry(entry);
    b_el_f1->GetEntry(entry);
    b_el_f3->GetEntry(entry);
    b_el_trackqoverp->GetEntry(entry);
    b_el_trackd0_physics->GetEntry(entry);
    b_el_TRTHighTOutliersRatio->GetEntry(entry);
    b_el_nTRTOutliers->GetEntry(entry);
    b_el_nSCTOutliers->GetEntry(entry);
    b_el_nPixelOutliers->GetEntry(entry);
    b_el_nBLayerOutliers->GetEntry(entry);
    b_el_nSiHits->GetEntry(entry);
//add for isem tight
   b_el_isConv->GetEntry(entry);   //!
   b_el_nConv->GetEntry(entry);   //!
   b_el_loose->GetEntry(entry);   //!
   b_el_medium->GetEntry(entry);   //!
   b_el_mediumIso->GetEntry(entry);   //!
   b_el_tight->GetEntry(entry);   //!
   b_el_tightIso->GetEntry(entry);   //!
   b_el_loosePP->GetEntry(entry);   //!
   b_el_mediumPP->GetEntry(entry);   //!
   b_el_tightPP->GetEntry(entry);   //!
   b_el_weta2->GetEntry(entry);   //!
   b_el_Etcone45->GetEntry(entry);   //!
   b_el_Etcone20->GetEntry(entry);   //!
   b_el_Etcone30->GetEntry(entry);   //!
   b_el_topoEtcone30->GetEntry(entry);   //!
   b_el_Etcone40->GetEntry(entry);   //!
   b_el_Etcone45->GetEntry(entry);   //!
   b_el_ptcone20->GetEntry(entry);   //!
   b_el_ptcone30->GetEntry(entry);   //!
//   b_el_Etcone40_pt_corrected->GetEntry(entry);   //! Not in susy
   b_el_expectHitInBLayer->GetEntry(entry);   //!
   b_el_reta->GetEntry(entry);   //!
   b_el_etas2->GetEntry(entry);   //!
   b_el_etap->GetEntry(entry);   //!
   b_el_cl_E->GetEntry(entry);   //!
   b_el_cl_pt->GetEntry(entry);   //!
   b_el_cl_eta->GetEntry(entry);   //!
   b_el_cl_phi->GetEntry(entry);   //!
   b_el_trackd0->GetEntry(entry);   //!
   b_el_ED_median->GetEntry(entry); //! 
//   b_el_trackz0->GetEntry(entry);   //!
   b_el_trackphi->GetEntry(entry);   //!
   b_el_tracktheta->GetEntry(entry);   //!
   b_el_tracketa->GetEntry(entry);   //!
   b_el_nBLHits->GetEntry(entry);   //!
   b_el_nPixHits->GetEntry(entry);   //!
   b_el_nSCTHits->GetEntry(entry);   //!
   b_el_nTRTHits->GetEntry(entry);   //!
   b_el_trackd0pv->GetEntry(entry);   //!
   b_el_trackz0pv->GetEntry(entry);   //!
   b_el_tracksigd0pv->GetEntry(entry);   //!
   b_el_tracksigz0pv->GetEntry(entry);   //!
   b_el_hastrack->GetEntry(entry);
   if(b_el_trackd0pvunbiased)b_el_trackd0pvunbiased->GetEntry(entry);   //!
   if(b_el_tracksigd0pvunbiased)b_el_tracksigd0pvunbiased->GetEntry(entry);   //!

   b_EF_e24vhi_medium1->GetEntry(entry);   //!
   b_EF_mu24i_tight->GetEntry(entry);   //!
   b_EF_mu36_tight->GetEntry(entry);   //!
   b_EF_e60_medium1->GetEntry(entry);
   if(b_EF_xe80T_tclcw_loose)b_EF_xe80T_tclcw_loose->GetEntry(entry);   //!
   if(b_EF_xe80_tclcw_loose)b_EF_xe80_tclcw_loose->GetEntry(entry); 


   b_mu_calo_E->GetEntry(entry);
   b_mu_calo_n->GetEntry(entry);
   b_mu_calo_pt->GetEntry(entry);
   b_mu_calo_eta->GetEntry(entry);
   b_mu_calo_phi->GetEntry(entry);
   b_mu_calo_charge->GetEntry(entry);
   b_mu_calo_author->GetEntry(entry);
   b_mu_calo_ptcone20->GetEntry(entry);
   b_mu_calo_medium->GetEntry(entry);
   b_mu_calo_nBLHits->GetEntry(entry);
   b_mu_calo_expectBLayerHit->GetEntry(entry);
   b_mu_calo_nPixelDeadSensors->GetEntry(entry);
   b_mu_calo_nSCTDeadSensors->GetEntry(entry);
   b_mu_calo_nPixHoles->GetEntry(entry);
   b_mu_calo_nSCTHoles->GetEntry(entry);
   b_mu_calo_nPixHits->GetEntry(entry);
   b_mu_calo_nSCTHits->GetEntry(entry);
   b_mu_calo_nTRTHits->GetEntry(entry);
   b_mu_calo_nTRTOutliers->GetEntry(entry);
   b_mu_calo_caloLRLikelihood->GetEntry(entry);
   b_mu_calo_caloMuonIdTag->GetEntry(entry);
   b_mu_muid_n->GetEntry(entry);   //!
   b_mu_muid_E->GetEntry(entry);   //!
   b_mu_muid_pt->GetEntry(entry);   //!
   b_mu_muid_m->GetEntry(entry);   //!
   b_mu_muid_eta->GetEntry(entry);   //!
   b_mu_muid_phi->GetEntry(entry);   //!
   b_mu_muid_px->GetEntry(entry);   //!
   b_mu_muid_py->GetEntry(entry);   //!
   b_mu_muid_pz->GetEntry(entry);   //!
   b_mu_muid_charge->GetEntry(entry);   //!
   b_mu_muid_allauthor->GetEntry(entry);   //!
   b_mu_muid_author->GetEntry(entry);   //!
   b_mu_muid_matchchi2->GetEntry(entry);   //!
   b_mu_muid_matchndof->GetEntry(entry);   //!
   b_mu_muid_etcone20->GetEntry(entry);   //!
   b_mu_muid_etcone30->GetEntry(entry);   //!
   b_mu_muid_etcone40->GetEntry(entry);   //!
   b_mu_muid_nucone20->GetEntry(entry);   //!
   b_mu_muid_nucone30->GetEntry(entry);   //!
   b_mu_muid_nucone40->GetEntry(entry);   //!
   b_mu_muid_ptcone20->GetEntry(entry);   //!
   b_mu_muid_ptcone30->GetEntry(entry);   //!
   b_mu_muid_ptcone40->GetEntry(entry);   //!
   b_mu_muid_energyLossPar->GetEntry(entry);   //!
   b_mu_muid_energyLossErr->GetEntry(entry);   //!
   b_mu_muid_bestMatch->GetEntry(entry);   //!
   b_mu_muid_isStandAloneMuon->GetEntry(entry);   //!
   b_mu_muid_isSiliconAssociatedForwardMuon->GetEntry(entry);   //!
   b_mu_muid_isCombinedMuon->GetEntry(entry);   //!
   b_mu_muid_isLowPtReconstructedMuon->GetEntry(entry);   //!
   b_mu_muid_loose->GetEntry(entry);   //!
   b_mu_muid_medium->GetEntry(entry);   //!
   b_mu_muid_tight->GetEntry(entry);   //!
   b_mu_muid_d0_exPV->GetEntry(entry);   //!
   b_mu_muid_z0_exPV->GetEntry(entry);   //!
   if(b_mu_muid_trackd0pvunbiased)b_mu_muid_trackd0pvunbiased->GetEntry(entry);
   if(b_mu_muid_trackz0pvunbiased)b_mu_muid_trackz0pvunbiased->GetEntry(entry);
   b_mu_muid_phi_exPV->GetEntry(entry);   //!
   b_mu_muid_theta_exPV->GetEntry(entry);   //!
   b_mu_muid_ms_d0->GetEntry(entry);   //!
   b_mu_muid_ms_z0->GetEntry(entry);   //!
   b_mu_muid_ms_phi->GetEntry(entry);   //!
   b_mu_muid_ms_theta->GetEntry(entry);   //!
   b_mu_muid_ms_qoverp->GetEntry(entry);   //!
//   b_mu_muid_id_d0->GetEntry(entry);   //!
//   b_mu_muid_id_z0->GetEntry(entry);   //!
   b_mu_muid_id_phi->GetEntry(entry);   //!
   b_mu_muid_id_theta->GetEntry(entry);   //!
   b_mu_muid_id_qoverp->GetEntry(entry);   //!
   b_mu_muid_me_d0->GetEntry(entry);   //!
   b_mu_muid_me_z0->GetEntry(entry);   //!
   b_mu_muid_me_phi->GetEntry(entry);   //!
   b_mu_muid_me_theta->GetEntry(entry);   //!
   b_mu_muid_me_theta_exPV->GetEntry(entry);   //!
   b_mu_muid_me_qoverp->GetEntry(entry);   //!
   b_mu_muid_me_qoverp_exPV->GetEntry(entry);   //!
   b_mu_muid_ie_d0->GetEntry(entry);   //!
   b_mu_muid_ie_z0->GetEntry(entry);   //!
   b_mu_muid_ie_phi->GetEntry(entry);   //!
   b_mu_muid_ie_theta->GetEntry(entry);   //!
   b_mu_muid_ie_theta_exPV->GetEntry(entry);   //!
   b_mu_muid_ie_qoverp->GetEntry(entry);   //!
   b_mu_muid_ie_qoverp_exPV->GetEntry(entry);   //!
   b_mu_muid_nOutliersOnTrack->GetEntry(entry);   //!
   b_mu_muid_nBLHits->GetEntry(entry);   //!
   b_mu_muid_nPixHits->GetEntry(entry);   //!
   b_mu_muid_nSCTHits->GetEntry(entry);   //!
   b_mu_muid_nTRTHits->GetEntry(entry);   //!
   b_mu_muid_nTRTHighTHits->GetEntry(entry);   //!
   b_mu_muid_nBLSharedHits->GetEntry(entry);   //!
   b_mu_muid_nPixSharedHits->GetEntry(entry);   //!
   b_mu_muid_nPixHoles->GetEntry(entry);   //!
   b_mu_muid_nSCTSharedHits->GetEntry(entry);   //!
   b_mu_muid_nSCTHoles->GetEntry(entry);   //!
   b_mu_muid_nTRTOutliers->GetEntry(entry);   //!
   b_mu_muid_nTRTHighTOutliers->GetEntry(entry);   //!
   b_mu_muid_nGangedPixels->GetEntry(entry);   //!
   b_mu_muid_nPixelDeadSensors->GetEntry(entry);   //!
   b_mu_muid_nSCTDeadSensors->GetEntry(entry);   //!
   b_mu_muid_nTRTDeadStraws->GetEntry(entry);   //!
   b_mu_muid_expectBLayerHit->GetEntry(entry);   //!
//   b_mu_muid_nMDTHits->GetEntry(entry);   //!
//   b_mu_muid_nMDTHoles->GetEntry(entry);   //!
//   b_mu_muid_nCSCEtaHits->GetEntry(entry);   //!
//   b_mu_muid_nCSCEtaHoles->GetEntry(entry);   //!
//   b_mu_muid_nCSCPhiHits->GetEntry(entry);   //!
//   b_mu_muid_nCSCPhiHoles->GetEntry(entry);   //!
//   b_mu_muid_nRPCEtaHits->GetEntry(entry);   //!
//   b_mu_muid_nRPCEtaHoles->GetEntry(entry);   //!
//   b_mu_muid_nRPCPhiHits->GetEntry(entry);   //!
//   b_mu_muid_nRPCPhiHoles->GetEntry(entry);   //!
//   b_mu_muid_nTGCEtaHits->GetEntry(entry);   //!
//   b_mu_muid_nTGCEtaHoles->GetEntry(entry);   //!
//   b_mu_muid_nTGCPhiHits->GetEntry(entry);   //!
//   b_mu_muid_nTGCPhiHoles->GetEntry(entry);   //!
   b_mu_muid_trackd0->GetEntry(entry);   //!
   b_mu_muid_trackz0->GetEntry(entry);   //!
//   b_mu_muid_trackfitchi2->GetEntry(entry);   //!  Not in susy
//   b_mu_muid_trackfitndof->GetEntry(entry);   //!  Not in susy 
//   b_mu_muid_hastrack->GetEntry(entry);   //!    Not in susy


   b_jet_AntiKt4TopoEM_n->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_E->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_pt->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_m->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_eta->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_phi->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_EtaOrigin->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_PhiOrigin->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_MOrigin->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_EtaOriginEM->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_PhiOriginEM->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_MOriginEM->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_WIDTH->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_n90->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_Timing->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_LArQuality->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_sumPtTrk->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_HECQuality->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_NegativeE->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_SamplingMax->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_fracSamplingMax->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_hecf->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_AverageLArQF->GetEntry(entry);
   b_jet_AntiKt4TopoEM_isUgly->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_isBadLoose->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_isBadMedium->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_isBadTight->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_MOriginEM->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_emfrac->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_EMJES->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_GCWJES->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_emscale_E->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_emscale_pt->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_emscale_m->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_emscale_eta->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_emscale_phi->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_jvtxf->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_jvtx_x->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_jvtx_y->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_jvtx_z->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_MOriginEM->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_flavor_weight_Comb->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_flavor_weight_IP3D->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_flavor_weight_SV0->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_flavor_weight_SV1->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_flavor_weight_MV1->GetEntry(entry);   //!
//   b_jet_AntiKt4TopoEM_flavor_weight_JetProb->GetEntry(entry);   //!
//   b_jet_AntiKt4TopoEM_flavor_weight_TrackCounting2D->GetEntry(entry);   //!
//   b_jet_AntiKt4TopoEM_flavor_weight_SoftMuonTag->GetEntry(entry);   //!
//   b_jet_AntiKt4TopoEM_flavor_weight_SoftElectronTag->GetEntry(entry);   //!
   b_jet_AntiKt4TopoEM_flavor_weight_JetFitterCOMBNN->GetEntry(entry);   //!

   b_MET_RefFinal_phi->GetEntry(entry);   //!
   b_MET_RefFinal_et->GetEntry(entry);   //!
   b_MET_RefFinal_sumet->GetEntry(entry);   //!
   b_MET_RefFinal_etx_CentralReg->GetEntry(entry);   //!
   b_MET_RefFinal_ety_CentralReg->GetEntry(entry);   //!
   b_MET_RefFinal_sumet_CentralReg->GetEntry(entry);   //!
   b_MET_RefFinal_phi_CentralReg->GetEntry(entry);   //!
   b_MET_RefFinal_etx_EndcapRegion->GetEntry(entry);   //!
   b_MET_RefFinal_ety_EndcapRegion->GetEntry(entry);   //!
   b_MET_RefFinal_sumet_EndcapRegion->GetEntry(entry);   //!
   b_MET_RefFinal_phi_EndcapRegion->GetEntry(entry);   //!
   b_MET_RefFinal_etx_ForwardReg->GetEntry(entry);   //!
   b_MET_RefFinal_ety_ForwardReg->GetEntry(entry);   //!
   b_MET_RefFinal_sumet_ForwardReg->GetEntry(entry);   //!
   b_MET_RefFinal_phi_ForwardReg->GetEntry(entry);   //!

   b_MET_Track_phi->GetEntry(entry);   //!
   b_MET_Track_et->GetEntry(entry);   //!
   b_MET_Track_sumet->GetEntry(entry);   //!
   b_MET_Track_etx_CentralReg->GetEntry(entry);   //!
   b_MET_Track_ety_CentralReg->GetEntry(entry);   //!
   b_MET_Track_sumet_CentralReg->GetEntry(entry);   //!
   b_MET_Track_phi_CentralReg->GetEntry(entry);   //!
   b_MET_Track_etx_EndcapRegion->GetEntry(entry);   //!
   b_MET_Track_ety_EndcapRegion->GetEntry(entry);   //!
   b_MET_Track_sumet_EndcapRegion->GetEntry(entry);   //!
   b_MET_Track_phi_EndcapRegion->GetEntry(entry);   //!
   b_MET_Track_etx_ForwardReg->GetEntry(entry);   //!
   b_MET_Track_ety_ForwardReg->GetEntry(entry);   //!
   b_MET_Track_sumet_ForwardReg->GetEntry(entry);   //!
   b_MET_Track_phi_ForwardReg->GetEntry(entry);   //!


   b_MET_SoftJets_phi->GetEntry(entry);   //!
   b_MET_SoftJets_et->GetEntry(entry);   //!
   b_MET_SoftJets_sumet->GetEntry(entry);   //!
   b_MET_SoftJets_etx_CentralReg->GetEntry(entry);   //!
   b_MET_SoftJets_ety_CentralReg->GetEntry(entry);   //!
   b_MET_SoftJets_sumet_CentralReg->GetEntry(entry);   //!
   b_MET_SoftJets_phi_CentralReg->GetEntry(entry);   //!
   b_MET_SoftJets_etx_EndcapRegion->GetEntry(entry);   //!
   b_MET_SoftJets_ety_EndcapRegion->GetEntry(entry);   //!
   b_MET_SoftJets_sumet_EndcapRegion->GetEntry(entry);   //!
   b_MET_SoftJets_phi_EndcapRegion->GetEntry(entry);   //!
   b_MET_SoftJets_etx_ForwardReg->GetEntry(entry);   //!
   b_MET_SoftJets_ety_ForwardReg->GetEntry(entry);   //!
   b_MET_SoftJets_sumet_ForwardReg->GetEntry(entry);   //!
   b_MET_SoftJets_phi_ForwardReg->GetEntry(entry);   //!

   if(!kIsData){
   b_MET_Truth_NonInt_etx->GetEntry(entry);   //!
   b_MET_Truth_NonInt_ety->GetEntry(entry);   //!
   b_MET_Truth_NonInt_phi->GetEntry(entry);   //!
   b_MET_Truth_NonInt_et->GetEntry(entry);   //!
   b_MET_Truth_NonInt_sumet->GetEntry(entry);   //!
   }
   b_MET_RefJet_phi->GetEntry(entry);   //!
   b_MET_RefJet_et->GetEntry(entry);   //!
   b_MET_RefJet_sumet->GetEntry(entry);   //!
   b_MET_RefJet_etx_CentralReg->GetEntry(entry);   //!
   b_MET_RefJet_ety_CentralReg->GetEntry(entry);   //!
   b_MET_RefJet_sumet_CentralReg->GetEntry(entry);   //!
   b_MET_RefJet_phi_CentralReg->GetEntry(entry);   //!
   b_MET_RefJet_etx_EndcapRegion->GetEntry(entry);   //!
   b_MET_RefJet_ety_EndcapRegion->GetEntry(entry);   //!
   b_MET_RefJet_sumet_EndcapRegion->GetEntry(entry);   //!
   b_MET_RefJet_phi_EndcapRegion->GetEntry(entry);   //!
   b_MET_RefJet_etx_ForwardReg->GetEntry(entry);   //!
   b_MET_RefJet_ety_ForwardReg->GetEntry(entry);   //!
   b_MET_RefJet_sumet_ForwardReg->GetEntry(entry);   //!
   b_MET_RefJet_phi_ForwardReg->GetEntry(entry);   //!

   b_MET_CellOut_Eflow_phi->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_et->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_sumet->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_etx_CentralReg->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_ety_CentralReg->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_sumet_CentralReg->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_phi_CentralReg->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_etx_EndcapRegion->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_ety_EndcapRegion->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_sumet_EndcapRegion->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_phi_EndcapRegion->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_etx_ForwardReg->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_ety_ForwardReg->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_sumet_ForwardReg->GetEntry(entry);   //!
   b_MET_CellOut_Eflow_phi_ForwardReg->GetEntry(entry);   //!

   b_MET_RefFinal_STVF_phi->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_et->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_sumet->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_etx_CentralReg->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_ety_CentralReg->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_sumet_CentralReg->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_phi_CentralReg->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_etx_EndcapRegion->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_ety_EndcapRegion->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_sumet_EndcapRegion->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_phi_EndcapRegion->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_etx_ForwardReg->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_ety_ForwardReg->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_sumet_ForwardReg->GetEntry(entry);   //!
   b_MET_RefFinal_STVF_phi_ForwardReg->GetEntry(entry);   //!

   b_vxp_n->GetEntry(entry);   //!
   b_vxp_x->GetEntry(entry);   //!
   b_vxp_y->GetEntry(entry);   //!
   b_vxp_z->GetEntry(entry);   //!
//   b_vxp_chi2->GetEntry(entry);   //!
   b_vxp_px->GetEntry(entry);   //!
   b_vxp_py->GetEntry(entry);   //!
   b_vxp_pz->GetEntry(entry);   //!
   b_vxp_E->GetEntry(entry);   //!
//   b_vxp_m->GetEntry(entry);   //!
   b_vxp_nTracks->GetEntry(entry);   //!
   b_vxp_sumPt->GetEntry(entry);   //!
//   b_vxp_type->GetEntry(entry);   //!
  if(!kIsData){
    b_mcevt_weight->GetEntry(entry);   //!
    b_jet_AntiKt4TopoEM_flavor_truth_label->GetEntry(entry);   //!
    b_trig_L1_TAV->GetEntry(entry);
  }
//For MET systematics
if(!kIsData){
b_jet_AntiKt4LCTopo_n->GetEntry(entry);   //!
b_jet_AntiKt4LCTopo_E->GetEntry(entry);   //!
b_jet_AntiKt4LCTopo_pt->GetEntry(entry);   //!
b_jet_AntiKt4LCTopo_m->GetEntry(entry);   //!
b_jet_AntiKt4LCTopo_eta->GetEntry(entry);   //!
b_jet_AntiKt4LCTopo_phi->GetEntry(entry);   //!
b_jet_AntiKt4LCTopo_MET_n->GetEntry(entry);   //!
b_jet_AntiKt4LCTopo_MET_wpx->GetEntry(entry);   //!
b_jet_AntiKt4LCTopo_MET_wpy->GetEntry(entry);   //!
b_jet_AntiKt4LCTopo_MET_wet->GetEntry(entry);   //!
b_jet_AntiKt4LCTopo_MET_statusWord->GetEntry(entry);   //!
b_jet_AntiKt4LCTopo_GCWJES->GetEntry(entry);   //!
b_MET_CellOut_Eflow_phi->GetEntry(entry);   //!
b_MET_CellOut_Eflow_et->GetEntry(entry);   //!
b_MET_CellOut_Eflow_sumet->GetEntry(entry);   //!
b_MET_CellOut_phi->GetEntry(entry);   //!
b_MET_CellOut_et->GetEntry(entry);   //!
b_MET_CellOut_sumet->GetEntry(entry);   //!

b_el_MET_wpx->GetEntry(entry);   //!
b_el_MET_wpy->GetEntry(entry);   //!
b_el_MET_wet->GetEntry(entry);   //!
b_el_MET_statusWord->GetEntry(entry);   //!
b_ph_pt->GetEntry(entry);   //!
b_ph_eta->GetEntry(entry);   //!
b_ph_phi->GetEntry(entry);   //!
b_ph_MET_wpx->GetEntry(entry);   //!
b_ph_MET_wpy->GetEntry(entry);   //!
b_ph_MET_wet->GetEntry(entry);   //!
b_ph_MET_statusWord->GetEntry(entry);   //!
b_tau_pt->GetEntry(entry);   //!
b_tau_eta->GetEntry(entry);   //!
b_tau_phi->GetEntry(entry);   //!
b_tau_MET_wpx->GetEntry(entry);   //!
b_tau_MET_wpy->GetEntry(entry);   //!
b_tau_MET_wet->GetEntry(entry);   //!
b_tau_MET_statusWord->GetEntry(entry);   //!
b_mu_muid_MET_wpx->GetEntry(entry);   //!
b_mu_muid_MET_wpy->GetEntry(entry);   //!
b_mu_muid_MET_wet->GetEntry(entry);   //!
b_mu_muid_MET_statusWord->GetEntry(entry);   //!
b_mu_staco_MET_wpx->GetEntry(entry);   //!
b_mu_staco_MET_wpy->GetEntry(entry);   //!
b_mu_staco_MET_wet->GetEntry(entry);   //!
b_mu_staco_MET_statusWord->GetEntry(entry);   //!


b_MET_RefMuon_phi->GetEntry(entry);   //!
b_MET_RefMuon_et->GetEntry(entry);   //!
b_MET_RefMuon_sumet->GetEntry(entry);   //!
b_MET_RefMuon_Track_Muid_sumet->GetEntry(entry);   //!

b_mu_staco_n->GetEntry(entry);   //!
b_mu_staco_E->GetEntry(entry);   //!
b_mu_staco_pt->GetEntry(entry);   //!
b_mu_staco_m->GetEntry(entry);   //!
b_mu_staco_eta->GetEntry(entry);   //!
b_mu_staco_phi->GetEntry(entry);   //!
b_mu_staco_ms_phi->GetEntry(entry);   //!
b_mu_staco_ms_theta->GetEntry(entry);   //!

//For trigger matching
/*
b_trig_EF_el_EF_e60_medium1->GetEntry(entry);;   //!
b_trig_EF_el_EF_e24vhi_medium1->GetEntry(entry);;   //!
b_trig_EF_el_n->GetEntry(entry);;   //!
b_trig_EF_el_eta->GetEntry(entry);;   //!
b_trig_EF_el_phi->GetEntry(entry);;   //!
*/
}
}
}
